theta=linspace(0,2*pi, 72);
F=@(x) f(x, theta(i),phi4);
Update=@(x) M(x, theta(i),phi4);
while( all(abs(dx)>lim) | firstloop==1)
warning 'Bad update. Aborting...'
x(1:4)=atan2( sin(x(1:4)) , cos(x(1:4)));
solutions=cell2mat(solutions);
solutions(:,1:20)
ans =
0.2505 0.2273 0.2054 0.1852 0.1665 0.1495 0.1342 0.1205 -1.3914 -1.3886 -1.3832 -1.3755 -1.3657 -1.3539 -1.3404 0.0657 0.0650 -1.2913 -1.2727 -1.2534
1.1719 1.1649 1.1619 1.1628 1.1675 1.1756 1.1870 1.2013 -2.5013 -2.5284 -2.5536 -2.5767 -2.5979 -2.6170 -2.6342 1.3896 1.4184 -2.6733 -2.6823 -2.6893
-1.1402 0.8784 0.7734 2.8885 -0.6993 -2.6619 -0.4288 1.4046 2.4737 -1.4770 1.7734 0.2960 -0.9963 -0.8606 1.4129 -0.8061 -2.7819 -2.7265 -1.8485 0.0196
0.9171 0.9085 0.8983 0.8866 0.8737 0.8598 0.8450 0.8294 0.7709 -2.6653 -2.6950 -2.7217 0.6895 2.9977 0.6579 -0.1126 -0.9554 3.0019 0.6113 0.6041
19.2667 18.8273 18.4260 18.0661 17.7507 17.4828 17.2651 17.1002 21.3498 -36.4085 -36.4210 -36.5029 21.1271 -62.8851 20.4115 119.0125 60.3767 -62.0026 18.8311 18.3472
6.4689 27.3019 31.5546 8.4895 3.5565 10.3017 1.9542 45.0152 31.9151 32.4906 51.2072 24.6759 6.1926 138.3313 -16.2680 8.5029 -95.8681 524.2912 -2.9438 89.7521
function [F,M]=preanalysis()
syms phi1 phi2 phi3 phi5 d s theta phi4 real
f1=25-s+d*cos(phi2)+3.1*cos(phi3);
f2=-5+d*sin(phi2)+3.1*sin(phi3);
f3=-25+6.3*cos(theta)+27*cos(phi1)-19.2*cos(phi2);
f4=11+6.3*sin(theta)+27*sin(phi1)-19.2*sin(phi2);
f5=-40+6.3*cos(theta)+(d-19.2)*cos(phi2)+29.1*cos(phi5)+16*cos(phi4);
f6=-24+6.3*sin(theta)+(d-19.2)*sin(phi2)+29.1*sin(phi5)+16*sin(phi4);
f=[f1, f2, f3, f4, f5, f6]';
x=[phi1 phi2 phi3 phi5 d s]';
M=matlabFunction(-J\f,'Vars',{x,theta,phi4});
F=matlabFunction(f,'Vars',{x,theta,phi4});