Why Dsolve considers my equations' variables constants!?
Ältere Kommentare anzeigen
clear all
Nx = 2; % number of state equations
Nu = 1; % number of control parameters
% x = sym('x%d', [1 Nx]);
% p = sym('p%d', [1 Nx]);
syms u t
syms x p [1 Nx]
% State equations
Dx(1) = x(2);
Dx(2) = -x(2) + u(1);
% Cost function inside the integral
g = 0.5*u(1)^2;
% Hamiltonian
H = g;
for i = 1 : Nx
H = H + p(i)*Dx(i);
end
% Costate equations
for i = 1 : Nx
Dp(i) = -diff(H,x(i));
end
% solve for control u
du = diff(H,u);
sol_u = solve(du,u);
% Substitute u to state equations
for i = 1 : Nx
Dx(i) = subs(Dx(i),u,sol_u);
end
% convert symbolic objects to strings for using 'dsolve'
% need ti automate this solving
clear x p
syms x(t) p(t) [1 Nx]
eqx = diff(x,t)==Dx
eqp = diff(p,t)==Dp
eq = [eqx,eqp];
sol_h = dsolve(eqx,eqp);
1 Kommentar
Ibrahim Bakry
am 11 Feb. 2024
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Solver Outputs and Iterative Display 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!