MATLAB: How to obtain minimum values from fsolve (maximum values not needed) and plot the result.

fsolveinterationminimumplot

Hi everyone, I wish to solve a system of transcendental equations containing sines and cosines (5 equations with 5 unknown angles) using fsolve. I have a parameter z which I will increase stepwise every time the equations are solved. How do I iterate fsolve for z from 0 to 50 in steps of 2?
I have
x0 = [x0;x0;x0;x0;x0];%Initial points
options = optimset('Display','iter');
[x,fval] = fsolve(@Man,x0,options)
z is a parameter in the function Man
Also the 5 equations (i.e. the function Man) are obtained by minimizing a function F with respect to the 5 angles, therefore I need only the values of the five angles that will give F a minimum value (maximum values not needed). How do I obtain the values of the angles that make F a minimum for each value of z and plot these minimum angles against z?
Thanks

Best Answer

First part:
x0 = [x0;x0;x0;x0;x0]; %Initial points

options = optimset('Display','iter');
zvals = 0 : 2 : 50;
numz = length(zvals);
x = zeros(5, numz);
fvals = zeros(1,numz);
for K = 1 : numz
z = zvals(K);
[x(:,K),fvals(K)] = fsolve(@(x) Man(x,z), x0, options)
end
Second part:
x0 = [x0;x0;x0;x0;x0]; %Initial points
zvals = 0 : 2 : 50;
numz = length(zvals);
x = zeros(5, numz);
fvals = zeros(1,numz);
for K = 1 : numz
z = zvals(K);
[x(:,K),fval(K)] = fmincon(@(x) F(x,z), x0, [], [], [], [], zeros(5,1), 2*pi*ones(5,1));
end
plot(zvals, fval)