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:
solve 2 equations with parameters

Subject: solve 2 equations with parameters

From: ewodul v Dulmen

Date: 11 Dec, 2009 10:04:03

Message: 1 of 9

Hello,

I'm trying to solve the following equation:


X = 1.5088;
Y = 1.266;

[q1,q2]=solve('cos(q1)+cos(q1+q2)=X', 'sin(q1)+sin(q1+q2)=Y');

Matlab gives the following error:

Warning: Explicit solution could not be found.

While there is a solution, because when I type

[q1,q2]=solve('cos(q1)+cos(q1+q2)=1.5088', 'sin(q1)+sin(q1+q2)=1.266');

(so without the X and Y in the equations) it gives me q1 = 0.52 and q2=0.349 which are the correct solutions. Is there a way to implement these X and Y in the solve equation? It's needed because I have to calculate a lot of angles for a trajectory.

Subject: solve 2 equations with parameters

From: Torsten Hennig

Date: 11 Dec, 2009 11:37:00

Message: 2 of 9

> Hello,
>
> I'm trying to solve the following equation:
>
>
> X = 1.5088;
> Y = 1.266;
>
> [q1,q2]=solve('cos(q1)+cos(q1+q2)=X',
> 'sin(q1)+sin(q1+q2)=Y');
>
> Matlab gives the following error:
>
> Warning: Explicit solution could not be found.
>
> While there is a solution, because when I type
>
> [q1,q2]=solve('cos(q1)+cos(q1+q2)=1.5088',
> 'sin(q1)+sin(q1+q2)=1.266');
>
> (so without the X and Y in the equations) it gives me
> q1 = 0.52 and q2=0.349 which are the correct
> solutions. Is there a way to implement these X and Y
> in the solve equation? It's needed because I have to
> calculate a lot of angles for a trajectory.

I'm not sure, but maybe this will work:

X = sym('1.5088');
Y = sym('1.266');
 
[q1,q2]=solve('cos(q1)+cos(q1+q2)=X',
'sin(q1)+sin(q1+q2)=Y');

Best wishes
Torsten.

Subject: solve 2 equations with parameters

From: Bruce

Date: 3 Jan, 2010 03:21:04

Message: 3 of 9

"ewodul v Dulmen" <ewodul@gmail.com> wrote in message <hft5ej$gm3$1@fred.mathworks.com>...
> Hello,
>
> I'm trying to solve the following equation:
>
>
> X = 1.5088;
> Y = 1.266;
>
> [q1,q2]=solve('cos(q1)+cos(q1+q2)=X', 'sin(q1)+sin(q1+q2)=Y');
>
> Matlab gives the following error:
>
> Warning: Explicit solution could not be found.
>
> While there is a solution, because when I type
>
> [q1,q2]=solve('cos(q1)+cos(q1+q2)=1.5088', 'sin(q1)+sin(q1+q2)=1.266');
>
> (so without the X and Y in the equations) it gives me q1 = 0.52 and q2=0.349 which are the correct solutions. Is there a way to implement these X and Y in the solve equation? It's needed because I have to calculate a lot of angles for a trajectory.

Hello Ewodul,

Actually the 'sym' command (Torsten gave) does not work either and gives the same warning msg.

Try the subs command...

>> a=subs('cos(q1)+cos(q1+q2)=X','X',1.5088)
 
a =
 
cos(q1 + q2) + cos(q1) = 943/625
 
>> b=subs('sin(q1)+sin(q1+q2)=Y','Y',1.266)
 
b =
 
sin(q1 + q2) + sin(q1) = 633/500
 
>> Q=solve(a,b);
>> [q1,q2]=solve(a,b);
>> [q1,q2]=solve(a,b)
 
q1 =
 
0.52347481128793986479835792628225237
 
 
q2 =
 
0.34928770183974407260094794663641128

These are the results you want. You can now use the subs commands in a loop
and generate angles galore with the 'solve' command.

Regards

Bruce

Subject: solve 2 equations with parameters

From: Greg Heath

Date: 3 Jan, 2010 04:21:16

Message: 4 of 9

On Dec 11 2009, 6:37 am, Torsten Hennig
<Torsten.Hen...@umsicht.fhg.de> wrote:
> > Hello,
>
> > I'm trying to solve the following equation:
>
> > X = 1.5088;
> > Y = 1.266;
>
> > [q1,q2]=solve('cos(q1)+cos(q1+q2)=X',
> > 'sin(q1)+sin(q1+q2)=Y');
>
> > Matlab gives the following error:
>
> > Warning: Explicit solution could not be found.
>
> > While there is a solution, because when I type
>
> > [q1,q2]=solve('cos(q1)+cos(q1+q2)=1.5088',
> > 'sin(q1)+sin(q1+q2)=1.266');
>
> > (so without the X and Y in the equations) it gives me
> > q1 = 0.52 and q2=0.349 which are the correct
> > solutions. Is there a way to implement these X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2+1/2/(4*X^2+4*Y^2)*
(4*X*Y^2+4*X^3-4*(-2*X^2*Y^4-X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))
*Y^2-2*X)*Y/(-X/(4*X^2+4*Y^2)*(4*X*Y^2+4*X^3-4*(-2*X^2*Y^4-
X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))+X^2+Y^2),1/2*X^2+1/2*Y^2-1)]
>>

Hope this helps.

Greg

Subject: solve 2 equations with parameters

From: Bruce

Date: 4 Jan, 2010 05:13:03

Message: 5 of 9

Greg Heath <heath@alumni.brown.edu> wrote in message <5f26b42c-4604-45e7-8b06-d8867f4bbcb4@p32g2000vbi.googlegroups.com>...
> On Dec 11 2009, 6:37 am, Torsten Hennig
> <Torsten.Hen...@umsicht.fhg.de> wrote:
> > > Hello,
> >
> > > I'm trying to solve the following equation:
> >
> > > X = 1.5088;
> > > Y = 1.266;
> >
> > > [q1,q2]=solve('cos(q1)+cos(q1+q2)=X',
> > > 'sin(q1)+sin(q1+q2)=Y');
> >
> > > Matlab gives the following error:
> >
> > > Warning: Explicit solution could not be found.
> >
> > > While there is a solution, because when I type
> >
> > > [q1,q2]=solve('cos(q1)+cos(q1+q2)=1.5088',
> > > 'sin(q1)+sin(q1+q2)=1.266');
> >
> > > (so without the X and Y in the equations) it gives me
> > > q1 = 0.52 and q2=0.349 which are the correct
> > > solutions. Is there a way to implement these X and Y
> > > in the solve equation? It's needed because I have to
> > > calculate a lot of angles for a trajectory.
> >
> > I'm not sure, but maybe this will work:
> >
> > X = sym('1.5088');
> > Y = sym('1.266');
> >
> > [q1,q2]=solve('cos(q1)+cos(q1+q2)=X',
> > 'sin(q1)+sin(q1+q2)=Y');
>
> It works
>
> >> [q1,q2]=solve('cos(q1)+cos(q1+q2)=X','sin(q1)+sin(q1+q2)=Y')
> q1 =
> [ atan((-X/(4*X^2+4*Y^2)*(4*X*Y^2+4*X^3+4*(-2*X^2*Y^4-
> X^4*Y^2+4*X^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is a symbolic answer you have produced, not a numeric one which is what is desired to produce the angles (in radians) for Ewodul's trajectories he mentioned. You have not produced a numeric answer because X and Y are not set to numeric values.
NB: If you had done this with the 'subs' command as I explained you would get a
numeric result.

This code of yours does not work either(to get a numeric result)...
> > X = sym('1.5088');
> > Y = sym('1.266');
it causes a warning message instead when run with your code above. I notice
you did not use it this time around...

In short you need the subs command to get a numeric result.

Regards

Bruce

Subject: solve 2 equations with parameters

From: Greg Heath

Date: 6 Jan, 2010 00:40:53

Message: 6 of 9

On Jan 4, 12:13 am, "Bruce " <braineor...@gmail.com> wrote:
> Greg Heath <he...@alumni.brown.edu> wrote in message <5f26b42c-4604-45e7-8b06-d8867f4bb...@p32g2000vbi.googlegroups.com>...
> > On Dec 11 2009, 6:37 am, Torsten Hennig
> > <Torsten.Hen...@umsicht.fhg.de> wrote:
> > > > Hello,
>
> > > > I'm trying tosolvethe following equation:
>
> > > >X= 1.5088;
> > > >Y= 1.266;
>
> > > > [q1,q2]=solve('cos(q1)+cos(q1+q2)=X',
> > > > 'sin(q1)+sin(q1+q2)=Y');
>
> > > > Matlab gives the following error:
>
> > > > Warning: Explicit solution could not be found.
>
> > > > While there is a solution, because when I type
>
> > > > [q1,q2]=solve('cos(q1)+cos(q1+q2)=1.5088',
> > > > 'sin(q1)+sin(q1+q2)=1.266');
>
> > > > (so without theXandYin the equations) it gives me
> > > >q1= 0.52 andq2=0.349 which are the correct
> > > > solutions. Is there a way to implement theseXandY
> > > > in thesolveequation? It's needed because I have to
> > > > calculate a lot of angles for a trajectory.
>
> > > I'm not sure, but maybe this will work:
>
> > >X= sym('1.5088');
> > >Y= sym('1.266');
>
> > > [q1,q2]=solve('cos(q1)+cos(q1+q2)=X',
> > > 'sin(q1)+sin(q1+q2)=Y');
>
> > It works
>
> > >> [q1,q2]=solve('cos(q1)+cos(q1+q2)=X','sin(q1)+sin(q1+q2)=Y')
> >q1=
> > [ atan((-X/(4*X^2+4*Y^2)*(4*X*Y^2+4*X^3+4*(-2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y^2-1)]
>
> > Hope this helps.
>
> > Greg
>
> Hello Greg
>
> No, that is a symbolic answer you have produced, not a numeric one which is what is desired to produce the angles (in radians) for Ewodul's trajectories he mentioned. You have not produced a numeric answer becauseXandYare not set to numeric values.

My point is:

Ewodul obtained an error message using the same code that
I used to obtain the symbolic solution. So my guess is that
he did something different than what he posted.

In addition:

In general one would use the explicit symbolic solution to obtain
numerical results instead of solving the equations again and again
for each of the gazillion times you want an answer.

However, considering the number of numerical operations
in the explicit solve solution, repeated solving could be faster.
I'll look into the speed factor when I get some time.

> NB: If you had done this with the 'subs' command as I explained you would get a
> numeric result.  
>
> This code of yours does not work either(to get a numeric result)...
> >> X= sym('1.5088');
> > >Y= sym('1.266');
>
> it causes a warning message instead when run with your code above. I notice
> you did not use it this time around...

> In short you need the subs command to get a numeric result.

You must be directing this at someone else. All I did was show
that the original code does produce an answer instead of an
error message.

Hope I made my self clear. My other point made above, refers
to the relative speed of a gazillion uses of subs or a gazillion
uses of solve.

Hope this helps.

Greg

Subject: solve 2 equations with parameters

From: Tom

Date: 13 Jan, 2010 22:22:03

Message: 7 of 9

"Bruce " <braineorama@gmail.com> wrote in message <hhrtcv$pj0$1@fred.mathworks.com>...
> Greg Heath <heath@alumni.brown.edu> wrote in message <5f26b42c-4604-45e7-8b06-d8867f4bbcb4@p32g2000vbi.googlegroups.com>...
> > On Dec 11 2009, 6:37 am, Torsten Hennig
> > <Torsten.Hen...@umsicht.fhg.de> wrote:
> > > > Hello,
> > >
> > > > I'm trying to solve the following equation:
> > >
> > > > X = 1.5088;
> > > > Y = 1.266;
> > >
> > > > [q1,q2]=solve('cos(q1)+cos(q1+q2)=X',
> > > > 'sin(q1)+sin(q1+q2)=Y');
> > >
> > > > Matlab gives the following error:
> > >
> > > > Warning: Explicit solution could not be found.
> > >
> > > > While there is a solution, because when I type
> > >
> > > > [q1,q2]=solve('cos(q1)+cos(q1+q2)=1.5088',
> > > > 'sin(q1)+sin(q1+q2)=1.266');
> > >
> > > > (so without the X and Y in the equations) it gives me
> > > > q1 = 0.52 and q2=0.349 which are the correct
> > > > solutions. Is there a way to implement these X and Y
> > > > in the solve equation? It's needed because I have to
> > > > calculate a lot of angles for a trajectory.
> > >
> > > I'm not sure, but maybe this will work:
> > >
> > > X = sym('1.5088');
> > > Y = sym('1.266');
> > >
> > > [q1,q2]=solve('cos(q1)+cos(q1+q2)=X',
> > > 'sin(q1)+sin(q1+q2)=Y');
> >
> > It works
> >
> > >> [q1,q2]=solve('cos(q1)+cos(q1+q2)=X','sin(q1)+sin(q1+q2)=Y')
> > q1 =
> > [ atan((-X/(4*X^2+4*Y^2)*(4*X*Y^2+4*X^3+4*(-2*X^2*Y^4-
> > X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))+X^2+Y^2)/Y,1/(4*X^2+4*Y^2)*
> > (4*X*Y^2+4*X^3+4*(-2*X^2*Y^4-X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2)))]
> > [ atan((-X/(4*X^2+4*Y^2)*(4*X*Y^2+4*X^3-4*(-2*X^2*Y^4-
> > X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))+X^2+Y^2)/Y,1/(4*X^2+4*Y^2)*
> > (4*X*Y^2+4*X^3-4*(-2*X^2*Y^4-X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2)))]
> > q2 =
> > [ atan((1/2/(4*X^2+4*Y^2)*(4*X*Y^2+4*X^3+4*(-2*X^2*Y^4-
> > X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))*X^2+1/2/(4*X^2+4*Y^2)*
> > (4*X*Y^2+4*X^3+4*(-2*X^2*Y^4-X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))
> > *Y^2-2*X)*Y/(-X/(4*X^2+4*Y^2)*(4*X*Y^2+4*X^3+4*(-2*X^2*Y^4-
> > X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))+X^2+Y^2),1/2*X^2+1/2*Y^2-1)]
> > [ atan((1/2/(4*X^2+4*Y^2)*(4*X*Y^2+4*X^3-4*(-2*X^2*Y^4-
> > X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))*X^2+1/2/(4*X^2+4*Y^2)*
> > (4*X*Y^2+4*X^3-4*(-2*X^2*Y^4-X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))
> > *Y^2-2*X)*Y/(-X/(4*X^2+4*Y^2)*(4*X*Y^2+4*X^3-4*(-2*X^2*Y^4-
> > X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))+X^2+Y^2),1/2*X^2+1/2*Y^2-1)]
> > >>
> >
> > Hope this helps.
> >
> > Greg
>
> Hello Greg
>
> No, that is a symbolic answer you have produced, not a numeric one which is what is desired to produce the angles (in radians) for Ewodul's trajectories he mentioned. You have not produced a numeric answer because X and Y are not set to numeric values.
> NB: If you had done this with the 'subs' command as I explained you would get a
> numeric result.
>
> This code of yours does not work either(to get a numeric result)...
> > > X = sym('1.5088');
> > > Y = sym('1.266');
> it causes a warning message instead when run with your code above. I notice
> you did not use it this time around...
>
> In short you need the subs command to get a numeric result.
>
> Regards
>
> Bruce

Can someone please explain the notation for me:
"atan((-X/(4*X^2+4*Y^2)*(4*X*Y^2+4*X^3+4*(-2*X^2*Y^4-X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))+X^2+Y^2)/Y,1/(4*X^2+4*Y^2)*
(4*X*Y^2+4*X^3+4*(-2*X^2*Y^4-X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2)))" contains a comma about half-way through. I can't for the life of me figure out what that means.

Thanks in advance.

Subject: solve 2 equations with parameters

From: Greg Heath

Date: 14 Jan, 2010 04:25:17

Message: 8 of 9

On Jan 13, 5:22 pm, "Tom " <tommacREM...@gmail.com> wrote:
> "Bruce " <braineor...@gmail.com> wrote in message <hhrtcv$pj...@fred.mathworks.com>...
> > Greg Heath <he...@alumni.brown.edu> wrote in message <5f26b42c-4604-45e7-8b06-d8867f4bb...@p32g2000vbi.googlegroups.com>...
> > > On Dec 11 2009, 6:37 am, Torsten Hennig
> > > <Torsten.Hen...@umsicht.fhg.de> wrote:
> > > > > Hello,
>
> > > > > I'm trying to solve the following equation:
>
> > > > > X = 1.5088;
> > > > > Y = 1.266;
>
> > > > > [q1,q2]=solve('cos(q1)+cos(q1+q2)=X',
> > > > > 'sin(q1)+sin(q1+q2)=Y');
>
> > > > > Matlab gives the following error:
>
> > > > > Warning: Explicit solution could not be found.
>
> > > > > While there is a solution, because when I type
>
> > > > > [q1,q2]=solve('cos(q1)+cos(q1+q2)=1.5088',
> > > > > 'sin(q1)+sin(q1+q2)=1.266');
>
> > > > > (so without the X and Y in the equations) it gives me
> > > > > q1 = 0.52 and q2=0.349 which are the correct
> > > > > solutions. Is there a way to implement these X and Y
> > > > > in the solve equation? It's needed because I have to
> > > > > calculate a lot of angles for a trajectory.
>
> > > > I'm not sure, but maybe this will work:
>
> > > > X = sym('1.5088');
> > > > Y = sym('1.266');
>
> > > > [q1,q2]=solve('cos(q1)+cos(q1+q2)=X',
> > > > 'sin(q1)+sin(q1+q2)=Y');
>
> > > It works
>
> > > >> [q1,q2]=solve('cos(q1)+cos(q1+q2)=X','sin(q1)+sin(q1+q2)=Y')
> > > q1 =
> > > [ atan((-X/(4*X^2+4*Y^2)*(4*X*Y^2+4*X^3+4*(-2*X^2*Y^4-
> > > X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))+X^2+Y^2)/Y,1/(4*X^2+4*Y^2)*
> > > (4*X*Y^2+4*X^3+4*(-2*X^2*Y^4-X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2)))]
> > > [ atan((-X/(4*X^2+4*Y^2)*(4*X*Y^2+4*X^3-4*(-2*X^2*Y^4-
> > > X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))+X^2+Y^2)/Y,1/(4*X^2+4*Y^2)*
> > > (4*X*Y^2+4*X^3-4*(-2*X^2*Y^4-X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2)))]
> > > q2 =
> > > [ atan((1/2/(4*X^2+4*Y^2)*(4*X*Y^2+4*X^3+4*(-2*X^2*Y^4-
> > > X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))*X^2+1/2/(4*X^2+4*Y^2)*
> > > (4*X*Y^2+4*X^3+4*(-2*X^2*Y^4-X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))
> > > *Y^2-2*X)*Y/(-X/(4*X^2+4*Y^2)*(4*X*Y^2+4*X^3+4*(-2*X^2*Y^4-
> > > X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))+X^2+Y^2),1/2*X^2+1/2*Y^2-1)]
> > > [ atan((1/2/(4*X^2+4*Y^2)*(4*X*Y^2+4*X^3-4*(-2*X^2*Y^4-
> > > X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))*X^2+1/2/(4*X^2+4*Y^2)*
> > > (4*X*Y^2+4*X^3-4*(-2*X^2*Y^4-X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))
> > > *Y^2-2*X)*Y/(-X/(4*X^2+4*Y^2)*(4*X*Y^2+4*X^3-4*(-2*X^2*Y^4-
> > > X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2))+X^2+Y^2),1/2*X^2+1/2*Y^2-1)]
>
> > > Hope this helps.
>
> > > Greg
>
> > Hello Greg
>
> > No, that is a symbolic answer you have produced, not a numeric one which is what is desired to produce the angles (in radians) for Ewodul's trajectories he mentioned. You have not produced a numeric answer because X and Y are not set to numeric values.
> > NB: If you had done this with the 'subs' command as I explained you would get a
> > numeric result.  
>
> > This code of yours does not work either(to get a numeric result)...
> > > > X = sym('1.5088');
> > > > Y = sym('1.266');
> > it causes a warning message instead when run with your code above. I notice
> > you did not use it this time around...
>
> > In short you need the subs command to get a numeric result.
>
> > Regards
>
> > Bruce
>
> Can someone please explain the notation for me:
> "atan((-X/(4*X^2+4*Y^2)*(4*X*Y^2+4*X^3+4*(-2*X^2*Y^4-X^4*Y^2+4*X^2*Y^2-Y^6+­4*Y^4)^(1/2))+X^2+Y^2)/Y,1/(4*X^2+4*Y^2)*
> (4*X*Y^2+4*X^3+4*(-2*X^2*Y^4-X^4*Y^2+4*X^2*Y^2-Y^6+4*Y^4)^(1/2)))"
> contains a comma about half-way through.  I can't for the life of me figure out what
> that means.

MAPLE'S ATAN(Y,X)
is equivalent to
MATLAB'S ATAN2(Y,X)

doc atan2
help atan2

Hope this helps,

Greg

Subject: solve 2 equations with parameters

From: Miroslav Balda

Date: 14 Jan, 2010 22:22:06

Message: 9 of 9

"ewodul v Dulmen" <ewodul@gmail.com> wrote in message <hft5ej$gm3$1@fred.mathworks.com>...
> Hello,
>
> I'm trying to solve the following equation:
>
>
> X = 1.5088;
> Y = 1.266;
>
> [q1,q2]=solve('cos(q1)+cos(q1+q2)=X', 'sin(q1)+sin(q1+q2)=Y');
>
> Matlab gives the following error:
>
> Warning: Explicit solution could not be found.
>
> While there is a solution, because when I type
>
> [q1,q2]=solve('cos(q1)+cos(q1+q2)=1.5088', 'sin(q1)+sin(q1+q2)=1.266');
>
> (so without the X and Y in the equations) it gives me q1 = 0.52 and q2=0.349 which are the correct solutions. Is there a way to implement these X and Y in the solve equation? It's needed because I have to calculate a lot of angles for a trajectory.

Hi,
If you are intersted only in mumerical solution, you do not need to use symbolic toolbox. I tried to solve your problem by my function LMFnlsq
     http://www.mathworks.com/matlabcentral/fileexchange/17534
applied in the following script:
% Ewodul
while 1
    X = inp('X',1.5088);
    if isnan(X), break, end
    Y = inp('Y',1.266);
    res = @(q) [cos(q(1)) + cos(q(1)+q(2)) - X
                sin(q(1)) + sin(q(1)+q(2)) - Y];
    q = LMFnlsq(res,[.5;.5])
end

The function inp for keyboard input with default value can be found at
     http://www.mathworks.com/matlabcentral/fileexchange/9033
It has been inserted here in order to have an easy way how to change X and Y. The while cycle ends when NaN is input for X. It is obvious from the following results:

>> Ewodul
          X = 1.5088 =>
          Y = 1.2660 =>
q =
    0.5235
    0.3493
          X = 1.5088 => 1.3
          Y = 1.2660 => .9
q =
   -0.0535
    1.3181
          X = 1.5088 => nan
I hope that it could help you.

Mira

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