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:
System of (two) non linear equations with noisy data

Subject: System of (two) non linear equations with noisy data

From: Thomas Britton

Date: 3 Oct, 2010 18:14:03

Message: 1 of 5

Dear All,

I'm getting a little stuck trying to work out how to use the optimization toolbox to sole my problem.

I have two equations:

testx=X.*d.*(cosd(phi)+cosd(theta).*sind(phi).*(RX-a)...
    /(c))+Y.*e.*(sind(phi)+cosd(phi).*...
    (RX-a)/(c));

testy=X.*d.*(sind(phi)+cosd(theta).*cosd(phi).*(RY-b)...
   /(c))+Y.*e.*(cosd(phi)+cosd(phi).*...
   (RY-b)/(c));

I have the following 'unknowns' (each are unknown exactly but I know a range which they should occupy and can have a fairly good initial guess at their values):

a, b, c, d, e
phi, theta

I have the following variables which I have measued testx and testy over:
X, Y, RX, RY

These measurements are noisy but I have lots of them (80k+ measurements). In essence I'd like to find a,b,c,d,e,phi and theta using some for of minimisation/optimisation.

Any suggestions on which function/routine to start with?

Subject: System of (two) non linear equations with noisy data

From: Innocent

Date: 3 Oct, 2010 18:31:06

Message: 2 of 5

i suggest you try to use fsolve for this example , type fsolve in your comand window for an exaple of this type of function.but also it seems you have a system of two equations with more unknown which might lead to the system being ill conditioned, when using fsolve.So try two check in the optimization toolbox for examples of methods you can try.

IK


"Thomas Britton" <benjamin.britton@materials.ox.ac.remove.uk> wrote in message <i8ah5b$k0g$1@fred.mathworks.com>...
> Dear All,
>
> I'm getting a little stuck trying to work out how to use the optimization toolbox to sole my problem.
>
> I have two equations:
>
> testx=X.*d.*(cosd(phi)+cosd(theta).*sind(phi).*(RX-a)...
> /(c))+Y.*e.*(sind(phi)+cosd(phi).*...
> (RX-a)/(c));
>
> testy=X.*d.*(sind(phi)+cosd(theta).*cosd(phi).*(RY-b)...
> /(c))+Y.*e.*(cosd(phi)+cosd(phi).*...
> (RY-b)/(c));
>
> I have the following 'unknowns' (each are unknown exactly but I know a range which they should occupy and can have a fairly good initial guess at their values):
>
> a, b, c, d, e
> phi, theta
>
> I have the following variables which I have measued testx and testy over:
> X, Y, RX, RY
>
> These measurements are noisy but I have lots of them (80k+ measurements). In essence I'd like to find a,b,c,d,e,phi and theta using some for of minimisation/optimisation.
>
> Any suggestions on which function/routine to start with?

Subject: System of (two) non linear equations with noisy data

From: Ross W

Date: 4 Oct, 2010 01:06:04

Message: 3 of 5

"Thomas Britton" <benjamin.britton@materials.ox.ac.remove.uk> wrote in message <i8ah5b$k0g$1@fred.mathworks.com>...
> Dear All,
>
> I'm getting a little stuck trying to work out how to use the optimization toolbox to sole my problem.
>
> I have two equations:
>
> testx=X.*d.*(cosd(phi)+cosd(theta).*sind(phi).*(RX-a)...
> /(c))+Y.*e.*(sind(phi)+cosd(phi).*...
> (RX-a)/(c));
>
> testy=X.*d.*(sind(phi)+cosd(theta).*cosd(phi).*(RY-b)...
> /(c))+Y.*e.*(cosd(phi)+cosd(phi).*...
> (RY-b)/(c));
>
> I have the following 'unknowns' (each are unknown exactly but I know a range which they should occupy and can have a fairly good initial guess at their values):
>
> a, b, c, d, e
> phi, theta
>
> I have the following variables which I have measued testx and testy over:
> X, Y, RX, RY
>
> These measurements are noisy but I have lots of them (80k+ measurements). In essence I'd like to find a,b,c,d,e,phi and theta using some for of minimisation/optimisation.
>
> Any suggestions on which function/routine to start with?

If you want to find values of a, b, c, d, e, phi, theta so that the sum of squared errors in testx and testy are minimised then you could use lsqnonlin (you imply you have the Optimization Toolbox).

Ross

Subject: System of (two) non linear equations with noisy data

From: Thomas Britton

Date: 4 Oct, 2010 11:25:06

Message: 4 of 5

Innocent and Ross - thanks for your responses.

@Innocent - I have multiple measurements, in effect making 160,000+ equations in total. I'm not sure of their independence though - so may fall into an inconsistency/underdetermined problem.

@Ross - your suggestions seems promising, though I'm not sure how to set up the function file for this.

I've written a function as the following, where Z(1:7) = [phi,theta,a,b,c,d,e]:
testdata1 contains X,Y, RX and RY in column form.

function [F] = surf_func(Z)

load testdata1

testshiftsx=X.*Z(3).*(cosd(Z(1))+cosd(Z(2)).*sind(Z(1)).*(RX-Z(5))...
    /(Z(7)))+Y.*Z(4).*(sind(Z(1))+cosd(Z(1)).*...
    (RX-Z(5))/(Z(7)));

testshiftsy=X.*Z(3).*(sind(Z(1))+cosd(Z(2)).*cosd(Z(1)).*(RY-Z(6))...
    /(Z(7)))+Y.*Z(4).*(cosd(Z(1))+cosd(Z(1)).*...
    (RY-Z(6))/(Z(7))););

F(1,:)=testshiftsx;
F(2,:)=testshiftsy;

Then I initiate my 'guessvector' to seed the problem.
Then I call the problem:
Out=lsqnonlin(@surf_func,guessvector);

However it's finding odd minima that shouldn't really be there.. (i.e. setting Z(3) and Z(4) to zero when I've seeded the problem with some test data that I've just added a bit of random noise to...

Thanks,
Ben

"Ross W" <rosswoodskiwi@hotmail.com> wrote in message <i8b99s$s0d$1@fred.mathworks.com>...
> "Thomas Britton" <benjamin.britton@materials.ox.ac.remove.uk> wrote in message <i8ah5b$k0g$1@fred.mathworks.com>...
> > Dear All,
> >
> > I'm getting a little stuck trying to work out how to use the optimization toolbox to sole my problem.
> >
> > I have two equations:
> >
> > testx=X.*d.*(cosd(phi)+cosd(theta).*sind(phi).*(RX-a)...
> > /(c))+Y.*e.*(sind(phi)+cosd(phi).*...
> > (RX-a)/(c));
> >
> > testy=X.*d.*(sind(phi)+cosd(theta).*cosd(phi).*(RY-b)...
> > /(c))+Y.*e.*(cosd(phi)+cosd(phi).*...
> > (RY-b)/(c));
> >
> > I have the following 'unknowns' (each are unknown exactly but I know a range which they should occupy and can have a fairly good initial guess at their values):
> >
> > a, b, c, d, e
> > phi, theta
> >
> > I have the following variables which I have measued testx and testy over:
> > X, Y, RX, RY
> >
> > These measurements are noisy but I have lots of them (80k+ measurements). In essence I'd like to find a,b,c,d,e,phi and theta using some for of minimisation/optimisation.
> >
> > Any suggestions on which function/routine to start with?
>
> If you want to find values of a, b, c, d, e, phi, theta so that the sum of squared errors in testx and testy are minimised then you could use lsqnonlin (you imply you have the Optimization Toolbox).
>
> Ross

Subject: System of (two) non linear equations with noisy data

From: Ross W

Date: 4 Oct, 2010 20:24:20

Message: 5 of 5

"Thomas Britton" <benjamin.britton@materials.ox.ac.remove.uk> wrote in message <i8cdii$jaf$1@fred.mathworks.com>...
> Innocent and Ross - thanks for your responses.
>
> @Innocent - I have multiple measurements, in effect making 160,000+ equations in total. I'm not sure of their independence though - so may fall into an inconsistency/underdetermined problem.
>
> @Ross - your suggestions seems promising, though I'm not sure how to set up the function file for this.
>
> I've written a function as the following, where Z(1:7) = [phi,theta,a,b,c,d,e]:
> testdata1 contains X,Y, RX and RY in column form.
>
> function [F] = surf_func(Z)
>
> load testdata1
>
> testshiftsx=X.*Z(3).*(cosd(Z(1))+cosd(Z(2)).*sind(Z(1)).*(RX-Z(5))...
> /(Z(7)))+Y.*Z(4).*(sind(Z(1))+cosd(Z(1)).*...
> (RX-Z(5))/(Z(7)));
>
> testshiftsy=X.*Z(3).*(sind(Z(1))+cosd(Z(2)).*cosd(Z(1)).*(RY-Z(6))...
> /(Z(7)))+Y.*Z(4).*(cosd(Z(1))+cosd(Z(1)).*...
> (RY-Z(6))/(Z(7))););
>
> F(1,:)=testshiftsx;
> F(2,:)=testshiftsy;
>
> Then I initiate my 'guessvector' to seed the problem.
> Then I call the problem:
> Out=lsqnonlin(@surf_func,guessvector);
>
> However it's finding odd minima that shouldn't really be there.. (i.e. setting Z(3) and Z(4) to zero when I've seeded the problem with some test data that I've just added a bit of random noise to...
>
> Thanks,
> Ben
>
> "Ross W" <rosswoodskiwi@hotmail.com> wrote in message <i8b99s$s0d$1@fred.mathworks.com>...
> > "Thomas Britton" <benjamin.britton@materials.ox.ac.remove.uk> wrote in message <i8ah5b$k0g$1@fred.mathworks.com>...
> > > Dear All,
> > >
> > > I'm getting a little stuck trying to work out how to use the optimization toolbox to sole my problem.
> > >
> > > I have two equations:
> > >
> > > testx=X.*d.*(cosd(phi)+cosd(theta).*sind(phi).*(RX-a)...
> > > /(c))+Y.*e.*(sind(phi)+cosd(phi).*...
> > > (RX-a)/(c));
> > >
> > > testy=X.*d.*(sind(phi)+cosd(theta).*cosd(phi).*(RY-b)...
> > > /(c))+Y.*e.*(cosd(phi)+cosd(phi).*...
> > > (RY-b)/(c));
> > >
> > > I have the following 'unknowns' (each are unknown exactly but I know a range which they should occupy and can have a fairly good initial guess at their values):
> > >
> > > a, b, c, d, e
> > > phi, theta
> > >
> > > I have the following variables which I have measued testx and testy over:
> > > X, Y, RX, RY
> > >
> > > These measurements are noisy but I have lots of them (80k+ measurements). In essence I'd like to find a,b,c,d,e,phi and theta using some for of minimisation/optimisation.
> > >
> > > Any suggestions on which function/routine to start with?
> >
> > If you want to find values of a, b, c, d, e, phi, theta so that the sum of squared errors in testx and testy are minimised then you could use lsqnonlin (you imply you have the Optimization Toolbox).
> >
> > Ross


please write your responses below other messages of the same thread, in this newsgroup.

perhaps you should write your function more like this so it computes the residuals:

 testshiftsx=X.*Z(3).*(cosd(Z(1))+cosd(Z(2)).*sind(Z(1)).*(RX-Z(5))...
     /(Z(7)))+Y.*Z(4).*(sind(Z(1))+cosd(Z(1)).*...
     (RX-Z(5))/(Z(7)))-testx;
 
 testshiftsy=X.*Z(3).*(sind(Z(1))+cosd(Z(2)).*cosd(Z(1)).*(RY-Z(6))...
     /(Z(7)))+Y.*Z(4).*(cosd(Z(1))+cosd(Z(1)).*...
     (RY-Z(6))/(Z(7)));)-testy;

now F needs to be a long column vector with all the residuals from both testx and testy

F=[testshiftx(:); testshifty(:)];

lsqnonlin will now try to minimse the sum of squares of all elements of F.

Ross

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