Solving a complex non-polynomial equation numerically
Show older comments
Hi!
I've got a problem with my equation that I try to solve numerically using both Matlab and Symbolic Toolbox. I'm after several source pages of MATLAB help, picked up a few tricks and tried most of them, still without satysfying result.
My goal is to solve set of three non-polynomial equations with q1, q2 and a3 angles. Those variables represent joint angles in my industrial manipulator and what I'm trying to achieve is to solve inverse kinematics of this model. My set of equations looks like this: http://imgur.com/bU6XjNP
I'm solving it with
numeric::solve([z1,z2,z3], [q1=x1..x2,q2=x3..x4,q3=x5..x6], MultiSolutions)
Changing the xn constant according to my needs. Yet I still get some odd results, the q1 var is off by approximately 0.1 rad, q2 and q3 being off by ~0.01 rad. I don't have much experience with numeric solve, so I just need information, should it supposed to look like that?
And, if not, what valid option do you suggest I should take next? Maybe transforming this equation to polynomial, maybe using a different toolbox?
Or, if trying to do this in Matlab, how can you limit your solutions when using solve()? I'm thinking of an equivalent to Symbolic Toolbox's 'assume()' and 'assumeAlso'.
I would be grateful for your help.
11 Comments
Walter Roberson
on 2 May 2013
I gather you don't want complex angles? ;-)
What values are you numerically expecting? What values are you numerically getting instead?
There are two solutions. To 16 digits they are
q1 = -0.1230313685824931
q2 = -0.01041672031622752
q3 = 0.01047178361108275
q1 = -0.1230313685824931
q2 = -1.556081042143456
q3 = 3.131120869978710
Krystian Meresinski
on 2 May 2013
Walter Roberson
on 2 May 2013
I am not sure what you mean by you "declared" those values? Your numeric::solve is phrased in terms of ranges ? Do you mean that you used starting points instead of ranges,
numeric::solve([z1,z2,z3], [q1=pi/2, q2=pi/4, q3=pi/2])
Krystian Meresinski
on 2 May 2013
Walter Roberson
on 2 May 2013
? You are not always using the equations shown in your link ?
The simultaneous equations from the link have four basic forms, two of which have complex components, and the other two are purely real. There are an infinite number of solutions for each form, as 2*Pi may be added to each of the components. Or, if you restrict to -Pi to +Pi, there are just the two solution sets. It does not matter what initial values you give for q1, q2, q3: if you are using the equations from the link you gave then you will get out one of the two forms.
Unless, that is, the three equations you gave in the link are not intended to be solved so that they produce simultaneous 0's. The [q1, q2, q3] values you list for your tries do not produce z1=0, z2=0, z3=0. If you want to solve for z1=c1, z2=c2, z3=c3, the equations to solve would need to be modified slightly.
Krystian Meresinski
on 3 May 2013
Walter Roberson
on 3 May 2013
You have 3 simultaneous equations in 3 unknowns. It does not matter what name you use for the variables, you can only get out one of the two solution, each of which is independent of any inputs. So there isn't any point in solving more than once. No matter where you start,
q1 = atan2((-17143410277150627991818509780672/329744835594954952182857248581305-(53455559442295377498539/9754511726569957395473283127532164510)*1995542027381856879969638845^(1/2)+(3634978042076085669900652/5812564922965486664333635831607170824270245319215)*(37212840512754418045379671385574061533108439895+901163555031209973151049476981568*1995542027381856879969638845^(1/2))^(1/2)+(94711015027693021802/61991131519306304330620269)*(1158590836/22340749-(1/236030013185)*1995542027381856879969638845^(1/2)+(136/281293377641699029772705)*(37212840512754418045379671385574061533108439895+901163555031209973151049476981568*1995542027381856879969638845^(1/2))^(1/2))^2-(1449066611454943735/123982263038612608661240538)*(1158590836/22340749-(1/236030013185)*1995542027381856879969638845^(1/2)+(136/281293377641699029772705)*(37212840512754418045379671385574061533108439895+901163555031209973151049476981568*1995542027381856879969638845^(1/2))^(1/2))^3)/(138638013545652904629488818226304/329744835594954952182857248581305+(216146392527542178581049/4877255863284978697736641563766082255)*1995542027381856879969638845^(1/2)-(29395909383745736287022664/5812564922965486664333635831607170824270245319215)*(37212840512754418045379671385574061533108439895+901163555031209973151049476981568*1995542027381856879969638845^(1/2))^(1/2)-(255307953552911623988/20663710506435434776873423)*(1158590836/22340749-(1/236030013185)*1995542027381856879969638845^(1/2)+(136/281293377641699029772705)*(37212840512754418045379671385574061533108439895+901163555031209973151049476981568*1995542027381856879969638845^(1/2))^(1/2))^2+(1953089780656663295/20663710506435434776873423)*(1158590836/22340749-(1/236030013185)*1995542027381856879969638845^(1/2)+(136/281293377641699029772705)*(37212840512754418045379671385574061533108439895+901163555031209973151049476981568*1995542027381856879969638845^(1/2))^(1/2))^3))
Krystian Meresinski
on 3 May 2013
Walter Roberson
on 3 May 2013
I solve()'d analytically instead of numerically.
Krystian Meresinski
on 3 May 2013
Walter Roberson
on 3 May 2013
That looks plausible at first look, but I did not compare it in detail. Notice that the definition of z5 involves the roots of a quartic: as quartics can be solved analytically, you can pull out the four analytic solutions without the RootOf().
However, the solution I am looking at via Maple uses arctan() with two parameters, which corresponds to the MuPad arctan (except perhaps with the elements reversed.) MuPAD's arctan() in turn would become the MATLAB atan2() routine if you were working on numeric parameters instead of symbolic. The difference is that the two-parameter arctan() is localized to quadrant whereas the one-parameter version is not.
Answers (0)
Categories
Find more on Numeric Solvers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!