Symbolic math Tool box "diff" and "dsolve" for optimal control
Ältere Kommentare anzeigen
This is a simple optimal control problem where I have to differentialte the hamiltonian w.r.t "u" and substitute into the state equation . the confusion is with "diff" dunction which wants me to declare the symbolic variables as "syms x1 x2 p1 p2 u " etc where as "dsolve" wants me to declare as "syms x1(t) x2(t) p1(t) p2(t) u(t)" .
What I want to do is to find the partial derivative of the Hamiltonian w.r.t "u" and substitute back in the state equation and obtain the ode , then use "dsolve" and solve the state and costate . But I see dsolve wants me to declare as said above and hence I am unable to supply BC's as mentioned in the website https://www.mathworks.com/help/symbolic/solve-a-system-of-differential-equations.html. Any work around for this ? the initial conditions are x1(0) = x2(0) = 0; final x1(2)=5 and x2(2) =2 . I have shown here till the sustitution which works fine . But I want to use dsolve for the state and costate odes and supply the conditions and solve symbolically . i dont want to use the old "string" method whose is said will be removed in future
If I declare as "syms x1(t) x2(t) p1(t) p2(t) u(t)" "diff" function wont work with this error
Error using sym/diff (line 26)
Arguments, except for the first, must not be symbolic functions.
clear all ;close all
syms x1 x2 p1 p2 u
% Write the Hamiltonian
H = (1/2)*u^2 + p1*x2 - p2*x2 + p2*u;
% --------------------- Necessary COnditions -------------------------
%State Equations (I have substituted directly)
x1dot = x2;
x2dot = -x2 + u;
% Costate Equations (I wanted to experiment with diff ) - for my other large problem
p1dot = -diff(H,x1);
p2dot = -diff(H,x2);
% COntrol Equations
dHdu = diff(H,u);
% -----------------------------------------------------------------------
sol_u = solve(dHdu,u);
% Substitute u in second state equation
x2dot = subs(x2dot,u,sol_u);
% here I have to collect x1dot;x2dot;p1dot;p2dot as four odes and use dsolve
1 Kommentar
Prateek Tiwari
am 19 Mai 2020
Even I have a similar problem in solving the hamiltonian function.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!