If you have symbolic toolbox, use:
syms u1 u2 up2 l1 l2 xa ya xpa ypa ap0
x = sym('x', [1 3]);
eqns(1) = cos(u1)*l1 + cos(u2)*l2 - xa;
eqns(2) = sin(u1)*l1 + sin(u2)*l2 - ya;
eqns(3) = ap0 -(xpa*cos(u2))/(4*(cos(u1)*sin(u2) - cos(u2)*sin(u1))) +...
(ypa*sin(u2))/(4*(cos(u1)*sin(u2) - cos(u2)*sin(u1)));
eqns(4) = up2 + (xpa*cos(u1))/(4*(cos(u1)*sin(u2) - cos(u2)*sin(u1))) -...
(ypa*sin(u1))/(4*(cos(u1)*sin(u2) - cos(u2)*sin(u1)));
eqns = subs(eqns,[u1, u2, up2],[x(1), x(2), x(3)]);
fun = matlabFunction(eqns,'vars',{x,'l1','l2','xa','ya','xpa','ypa'...
'ap0'});
fun = str2func(replace(func2str(fun),"in1","x"));
Then fun is a function handle that you can work with:
l1 = 3;
l2 = 2;
xa = 3;
ya = 6;
xpa = 0.5;
ypa = -1;
ap0 = 5.7;
opts = optimoptions('fsolve','Algorithm','Levenberg-Marquardt');
sol = fsolve(@(x)fun(x,l1,l2,xa,ya,xpa,ypa,ap0),rand(1,3),opts)
test_results = fun(sol,l1,l2,xa,ya,xpa,ypa,ap0)
For my fantasy values there was not a good result - you have to check using your values and also have a look at the correct implementation of the equations in the first part. They should all be formulated as F = 0, to work with them using fsolve.
2 Comments
Stephan (view profile)
Direct link to this comment
https://la.mathworks.com/matlabcentral/answers/487888-solve-overspecified-equation-system#comment_760937
Nikolas Haimerl (view profile)
Direct link to this comment
https://la.mathworks.com/matlabcentral/answers/487888-solve-overspecified-equation-system#comment_760943
Sign in to comment.