Hello, I'm trying to get Matlab to give me the the same results that I am able get in Maple.
I have an equation with two unknowns, x and y. They are both angles and I am trying to find the solutions to that equation. If i use a package named DirectSearch in Maple i can get exactly what i want. I can set constraints on x and y. I can choose number of solutions and the distance between them.
In Matlab i have tried to use multistart, nonlcon and various functions from the optimization toolbox. But i can't get Matlab to find the solutions(x and y) which gives me zero. In other words i want the solutions which gives me a function value that equals zero. Here is an example of what i have tried so far
clear all, clc, format compact, format shortms = MultiStart;opts = optimoptions(@fmincon,'Algorithm','interior-point');fun = @(x) (((0.2284963440e-1*sin(x(1))*cos(x(2))*sin(x(2))+0.2284963440e-1*cos(x(1))... *sin(x(2))^2+(-0.2944413003e-1*cos(x(1))-0.2777543403e-2*sin(x(1)))*sin(x(2)))... *sqrt(3.2186761*10^7-3.1957320*10^7*cos(x(2)-.1584758961))-56.24910000*sin(x(1))... *cos(x(2))*sin(x(2))-56.24910000*cos(x(1))*sin(x(2))^2+(72.48281461*cos(x(1))+6.837497436*sin(x(1)))... *sin(x(2)))*cos(-1.*acos((6561.744237*(cos(x(2)-.1584758961)-.9222315718))... /sqrt(3.2186761*10^7-3.1957320*10^7*cos(x(2)-.1584758961)))+x(2))+((-0.2284963440e-1*sin(x(1))... *cos(x(2))^2+(-0.2284963440e-1*cos(x(1))*sin(x(2))+0.2944413003e-1*cos(x(1))+0.2777543403e-2... *sin(x(1)))*cos(x(2)))*sqrt(3.2186761*10^7-3.1957320*10^7*cos(x(2)-.1584758961))+56.24910000*sin(x(1))... *cos(x(2))^2+(-72.48281461*cos(x(1))-6.837497436*sin(x(1))+56.24910000*cos(x(1))*sin(x(2)))*cos(x(2)))... *sin(-1.*acos((6561.744237*(cos(x(2)-.1584758961)-.9222315718))... /sqrt(3.2186761*10^7-3.1957320*10^7*cos(x(2)-.1584758961)))+x(2))-.1112132575... *sin(x(1))*cos(x(2))^2+(.1433098472*cos(x(1))-.1112132575*cos(x(1))... *sin(x(2))+.9563372292*sin(x(1)))*cos(x(2))+.9428184287*cos(x(1))*sin(x(2)))... /(sin(x(1))*cos(x(2))+cos(x(1))*sin(x(2)));%problem = createOptimProblem('fmincon','x0',[0,0],'objective',fun,'lb',[0.85,0.5],'ub',[1.35,0.85], 'options',opts);
problem2 = createOptimProblem('fmincon','x0',[0,0],'objective',fun,'lb',[0.85,0.5],'ub',[1.35,0.85],'nonlcon',@mycon, 'options',opts);%[xminm,fminm,flagm,outptm,manyminsm] = run(ms,problem,50)
[xminm,fminm,flagm,outptm,manyminsm] = run(ms,problem2,50)function [c,ceq] = mycon(x)c = [] ceq =@(x)(((0.2284963440e-1*sin(x(1))*cos(x(2))*sin(x(2))+0.2284963440e-1*cos(x(1))*... sin(x(2))^2+(-0.2944413003e-1*cos(x(1))-0.2777543403e-2*sin(x(1)))*sin(x(2)))*... sqrt(3.2186761*10^7-3.1957320*10^7*cos(x(2)-.1584758961))-56.24910000*sin(x(1))*cos(x(2))... *sin(x(2))-56.24910000*cos(x(1))*sin(x(2))^2+(72.48281461*cos(x(1))+6.837497436*sin(x(1)))... *sin(x(2)))*cos(-1.*acos((6561.744237*(cos(x(2)-.1584758961)-.9222315718))... /sqrt(3.2186761*10^7-3.1957320*10^7*cos(x(2)-.1584758961)))+x(2))+((-0.2284963440e-1... *sin(x(1))*cos(x(2))^2+(-0.2284963440e-1*cos(x(1))*sin(x(2))+0.2944413003e-1... *cos(x(1))+0.2777543403e-2*sin(x(1)))*cos(x(2)))*sqrt(3.2186761*10^7-3.1957320*10^7*cos(x(2)... -.1584758961))+66.2491*sin(x(1))*cos(x(2))^2+(-72.48281461*cos(x(1))-6.837497436*sin(x(1))... +56.24910000*cos(x(1))*sin(x(2)))*cos(x(2)))*sin(-1.*acos((6561.744237*(cos(x(2)-.1584758961)-.9222315718))... /sqrt(3.2186761*10^7-3.1957320*10^7*cos(x(2)-.1584758961)))+x(2))-.1112132575*sin(x(1))*... cos(x(2))^2+(.1433098472*cos(x(1))-.1112132575*cos(x(1))*sin(x(2))+.9563372292*sin(x(1)))*... cos(x(2))+.9428184287*cos(x(1))*sin(x(2)))/(sin(x(1))*cos(x(2))+cos(x(1))*sin(x(2)))end
Best Answer