How can I obtain minimum values from fsolve (maximum values not needed) and plot the result.
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Oladunjoye
am 4 Jan. 2014
Kommentiert: Oladunjoye
am 14 Jan. 2014
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 Kommentare
Roger Stafford
am 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?
Akzeptierte Antwort
Walter Roberson
am 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 Kommentare
Walter Roberson
am 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!