Optimisation of cost function
Mostrar comentarios más antiguos
I'm trying to optimise the cost function for a simple pendulum on a cart. I have written the following code that returns the value of J(cost function) fobs2.m
function [J,u_candidate_fnc] =fobs2(lambda)
sol=void(lambda(1),lambda(2),lambda(3),lambda(4));
t=0:0.001:4.452;
u_candidate_fnc=candidate_fnc(t,lambda);
J=(max(sol.y(1,:))-pi)^2+ abs(max(candidate_fnc)) + abs(max(sol.y(3,:)));
Candidate_fnc.m defines candidate function for acceleration of the cart as the input to the system.
function u=candidate_fnc(t,lambda)
Tf=4.4520;
w=2*pi/Tf;
u1=lambda(1)*sin(w*t);
u2=lambda(2)*sin(2*w*t);
u3=lambda(3)*sin(3*w*t);
u4=lambda(4)*sin(4*w*t);
u5=(-5*lambda(1) -5/2*lambda(2)-5/3*lambda(3)-5/4*lambda(4))*sin(5*w*t);
u=u1+u2+u3+u4+u5;
I used BVP solver to give me better trajectories using initial guesses. I've written the following code to store the new trajectories in sol. void.m:
function y=void(lambda1,lambda2,lambda3,lambda4)
lambda=[lambda1 lambda2 lambda3 lambda4];
t_opt=linspace(0,4452*0.001,4452)';
solinit = bvpinit(t_opt,@xinit_fcn,lambda);
sol = bvp4c(@system_odeset_fcn,@bc_function,solinit);
% disp('Lambda values: ')
y=sol;
when I run fobs2.m it says, not enough input arguments in sol=void(lambda(1),lambda(2),lambda(3),lambda(4)); and Undefined variable "sol".
3 comentarios
Walter Roberson
el 14 de Jun. de 2018
When you run fobs2, what are you passing to fobs2 on the command line?
Walter Roberson
el 14 de Jun. de 2018
At one point you had commented
lambda= [0.1 0.075 0.1 0.25]
but did you then invoke
fobs2(lambda)
or did you just expect fobs2 to find the variable named lambda that you had assigned to?
SARNENDU JATI
el 14 de Jun. de 2018
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Solver Outputs and Iterative Display en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!