How can I obtain minimum values from fsolve (maximum values not needed) and plot the result.

20 views (last 30 days)
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
  2 Comments
Roger Stafford
Roger Stafford on 7 Jan 2014
I think your description needs some clarification, Oladunjoye. You state that " the 5 equations (i.e. the function Man) are obtained by minimizing a function F with respect to the 5 angles ". Exactly what is it you adjust in these five equations in order to minimize F? It can't be z, since you have specified its 26 possible values. In spite of the phrase "with respect to the 5 angles" it makes no sense to adjust the five angles, since you are going to then turn around and readjust them so as to satisfy your five equations. There must be some other parameters in these equations you haven't told us about which you are adjusting. Moreover, once you have adjusted the angles so as to satisfy the equations using 'fsolve', they will no longer necessarily minimize F. How about expanding on your description so as to make all this more clear to us?
Oladunjoye
Oladunjoye on 14 Jan 2014
Dear Roger Stanford, Thank you for your interest in my problem. I have attached the problem in a document here. Regards.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 4 Jan 2014
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)
  3 Comments
Walter Roberson
Walter Roberson on 7 Jan 2014
x = cell(1, numz);
fvals = cell(1,numz);
then in the loop
[x{K}, fvals{K}] = fmincon(@(x) F(x,z), x0, [], [], [], [], zeros(5,1), 2*pi*ones(5,1));
After the loop,
plot(zvals, cell2mat(fvals))
I do not know at the moment which of the two arrays there were problems writing values to, so I am not positive that cell2mat(fvals) will give you exactly what you want. If not, if you could show size(fvals{1}) then I should be able to suggest something else.
With regards to the first part, you asked for the solutions to Man, not for the minima. The minima are what is found in the second part. The x values are not going to be the minima: the x values are going to be the angles at which the minima occurs, with the fvals being the value of the minima.
Oladunjoye
Oladunjoye on 14 Jan 2014
Dear Walter Robinson, Thanks for the code. It is working now but the second part is not giving the desires result. However, the first part is perfect. I wish to plot only the first, third and fifth angles against z. I have attached the full problem here. Regards

Sign in to comment.

More Answers (0)

Categories

Find more on Programming 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!