Steepest Ascent Method to find maximum

6 visualizaciones (últimos 30 días)
Syed Abdul Rafay
Syed Abdul Rafay el 13 de Dic. de 2022
Comentada: Torsten el 13 de Dic. de 2022
I am looking for a problem in my implementation for steepest ascent method. My answer is in a long equation form with h in it. But I am calculating h in the loop still ther is no value of it for the answer. The solution is at the end of the function
function STPAscent(x,theta,TC)
x0 =1500;
theta0=pi/6;
i=0;
i_max=100;
ea=5;
es=1;
while (es<double(subs(ea)) && i<i_max)
fx = tan(theta0)/(2*100^2*(cos(theta0))^2) + (2*9.81*x0)/(2*100^2*(cos(theta0))^2); % derivative wrt "x"
ftheta= x0*(sin(theta0)*(100*sin(theta0)+981*x0*cos(theta0))+50)/(1000000*(cos(theta0))^4); % derivative wrt "theta"
syms h
x=x0+fx*h;
theta=theta0+ftheta*h;
f= 1000 + (x*tan(theta))/(2*100^2*(cos(theta))^2) + (9.81*x^2)/(2*100^2*(cos(theta))^2);
c=diff(f,h);
assume(h,'clear')
h=solve(c==0,h,'PrincipalValue',true);
x_new=x+fx*h;
theta_new=theta0+ftheta*h;
ea=abs((x_new-x0)/x_new)*100;
x0=x_new;
theta0=theta_new;
i=i+1;
end
fxtheta = 1000 + (x0*tan(theta0))/(2*100^2*(cos(theta0))^2) + (9.81*x0^2)/(2*100^2*(cos(theta0))^2)
simplify(fxtheta)
end
Command Window
Warning: Unable to solve symbolically. Returning a numeric
solution using vpasolve.
> In sym/solve (line 304)
In STPAscent (line 18)
fxtheta =
(981*((8836235812531391*h)/4503599627370496 + 1499.9993954193889930311396801317)^2)/(2000000*cos(pi/6 - 0.52363352427033321420523588398365)^2) + (tan(pi/6 - 0.52363352427033321420523588398365)*((8836235812531391*h)/4503599627370496 + 1499.9993954193889930311396801317))/(20000*cos(pi/6 - 0.52363352427033321420523588398365)^2) + 1000
ans =
0.0018882263675909642813601409431637*h^2 + 2.8871384744661982638760370739896*h + 2103.6241090862540686603690416302
  3 comentarios
Syed Abdul Rafay
Syed Abdul Rafay el 13 de Dic. de 2022
But h is unknown and if I don't use symbolic function the code doeasn't proceed with error unrecognized variable 'h'. I have to use the h value calculate in x new to get a updated value of x .
Torsten
Torsten el 13 de Dic. de 2022
You can define a function dependent on an unknown h for which you want to find the root and use "fzero" or "fsolve" to solve for h.
That's exactly what "solve" will do in your case because it doesn't find an analytical solution for h.

Iniciar sesión para comentar.

Respuestas (0)

Productos


Versión

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by