Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Nonlinear Least Squares problem

Subject: Nonlinear Least Squares problem

From: AJ Smith

Date: 29 Jan, 2009 18:42:02

Message: 1 of 6

I'm working on solving a system of non-linear equations in MATLAB. Currently I am able to solve a system of 3 equations with 3 unknowns using Newton's method (with a jacobian, etc). What I want to do is take 4 or more equations (still with 3 unknowns) and solve them, but when I do, the jacobian is non-square, therefore not invertable (also not compatible with the backslash operation). Does anybody have any ideas on how to go about soving this? Here are my equations, 'i' going from 1 to the number of equations I want. The knowns are a,b,and theta and the unknowns are x, y, and phi.

0 = a(i) - x - (b(i) - y)*tan(theta(i) + phi)

Thanks!

AJ

Subject: Nonlinear Least Squares problem

From: Miroslav Balda

Date: 29 Jan, 2009 21:32:02

Message: 2 of 6

"AJ Smith" <ajsmith_15@hotmail.com> wrote in message <glst9p$dql$1@fred.mathworks.com>...
> I'm working on solving a system of non-linear equations in MATLAB. Currently I am able to solve a system of 3 equations with 3 unknowns using Newton's method (with a jacobian, etc). What I want to do is take 4 or more equations (still with 3 unknowns) and solve them, but when I do, the jacobian is non-square, therefore not invertable (also not compatible with the backslash operation). Does anybody have any ideas on how to go about soving this? Here are my equations, 'i' going from 1 to the number of equations I want. The knowns are a,b,and theta and the unknowns are x, y, and phi.
>
> 0 = a(i) - x - (b(i) - y)*tan(theta(i) + phi)
>
> Thanks!
>
> AJ

Hi,
In this case you may apply my function LMFnlsq (FEX Id 17534), which is ready just for thiese tastks.
Good luck.
Mira

Subject: Nonlinear Least Squares problem

From: Roger Stafford

Date: 29 Jan, 2009 22:37:02

Message: 3 of 6

"AJ Smith" <ajsmith_15@hotmail.com> wrote in message <glst9p$dql$1@fred.mathworks.com>...
> I'm working on solving a system of non-linear equations in MATLAB. Currently I am able to solve a system of 3 equations with 3 unknowns using Newton's method (with a jacobian, etc). What I want to do is take 4 or more equations (still with 3 unknowns) and solve them, but when I do, the jacobian is non-square, therefore not invertable (also not compatible with the backslash operation). Does anybody have any ideas on how to go about soving this? Here are my equations, 'i' going from 1 to the number of equations I want. The knowns are a,b,and theta and the unknowns are x, y, and phi.
>
> 0 = a(i) - x - (b(i) - y)*tan(theta(i) + phi)
>
> Thanks!
>
> AJ

  With four or more equations and three unknowns, you will probably have to use some kind of least squares method, because you are unlikely to find an exact solution. It might be better to find the least sum of squares of the four quantities in this form:

 (a(i)-x)*cos(theta(i)+phi) + (b(i)-y)*sin(theta(i)+phi)

  You will note that these are linear in x and y. For any given phi, it is possible to find the least sum of those squares using the backslash operator, thereby eliminating x and y from the problem. If you write a function to do this, you could use the value of that least squares sum as an objective function to be minimized with phi as your single value to be varied. For the optimization functions, one unknown is generally better than three.

Roger Stafford

Subject: Nonlinear Least Squares problem

From: Roger Stafford

Date: 29 Jan, 2009 23:04:02

Message: 4 of 6

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gltb2e$cgt$1@fred.mathworks.com>...
> .......
> (a(i)-x)*cos(theta(i)+phi) + (b(i)-y)*sin(theta(i)+phi)
> .......

  I meant

 (a(i)-x)*cos(theta(i)+phi) - (b(i)-y)*sin(theta(i)+phi)

Roger Stafford

Subject: Nonlinear Least Squares problem

From: Roger Stafford

Date: 30 Jan, 2009 02:07:01

Message: 5 of 6

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gltb2e$cgt$1@fred.mathworks.com>...
> ......
> You will note that these are linear in x and y. For any given phi, it is possible to find the least sum of those squares using the backslash operator, thereby eliminating x and y from the problem.
> ......

  I shouldn't have said to use the backslash in computing the least sum of squares with optimum x and y. There is a relatively simple method of computing this sum without ever bothering to find x and y. It is done as follows.

  For any given phi we are adjusting x and y so as to produce the minimum value of

 m = sum(((a-x).*cos(theta+phi)-(b-y).*sin(theta+phi)).^2)

where the quantities a, b, and theta are vectors, presumably of length 4 or greater.

The desired result is obtained with these steps:

 A = cos(theta+phi);
 B = -sin(theta+phi);
 C = a.*cos(theta+phi)-b.*sin(theta+phi);
 p = sum(A.^2); q = sum(A.*B); r = sum(B.^2);
 s = sum(A.*C); t = sum(B.*C); u = sum(C.^2);
 m = u-(p*t^2-2*q*s*t+r*s^2)/(p*r-q^2);

  It is this value m that can be the objective function of phi which is to be minimized by varying phi.

  Once the optimum phi has been found, x and y can be found by:

 x = (r*s-q*t)/(p*r-q^2);
 y = (p*t-q*s)/(p*r-q^2);

where A, B, C, p, q, r, s, t, and u are computed as above.

Roger Stafford

Subject: Nonlinear Least Squares problem

From: AJ Smith

Date: 30 Jan, 2009 12:57:01

Message: 6 of 6

Thanks for the help everyone, I'll give those methods a shot!

AJ

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us