Optimal control problem with integral cost function and both initial and terminal conditions

19 Ansichten (letzte 30 Tage)
Hello everybody, I would like to implement in Matlab an optimal control theory problem I am studying for my thesis. The problem is quite complex, I will attach it here:
Minimize the cost functional J on the interval [0,T]
subject to
with constraints and boundary data
I didn't know where to start solving this problem, because of the mixed initial and terminal conditions, I searched online and I started from simple linear problems, managing to resolve them. But when I try to complicate things, inserting nonlinear dynamics I get an error, in particular it says 'Dot indexing is not supported for variables of this type'. I attach the code to explain how I am solving this simple problems, but my question is if the error is due to something I can fix or I have to change my strategy. In this case it would be really helpful to know to deal with it.
The code I am attaching (and for which I get the error) is for solving the problem:
with J(u) integral cost function and initial and terminal constraints
% State equations
syms x1 x2 p1 p2 u;
%dynamics
%Dx1=x2;
Dx1 = x1*x2; %non lineare
Dx2 = -x2 + u;
% Cost function inside the integral
syms g;
g = 0.5*u^2;
% Hamiltonian
syms p1 p2 H;
H = g + p1*Dx1 + p2*Dx2;
% Costate equations
Dp1 = -diff(H,x1); %creo il sistema
Dp2 = -diff(H,x2);
% solve for control u
du = diff(H,u);
sol_u= solve(du,u);
% Substitute u to state equations
Dx2 = subs(Dx2, u, sol_u);
% convert symbolic objects to strings for using ’dsolve’
eq1 = strcat('Dx1=',char(Dx1)); %concatena le stringhe
eq2 = strcat('Dx2=',char(Dx2));
eq3 = strcat('Dp1=',char(Dp1));
eq4 = strcat('Dp2=',char(Dp2));
sol_h = dsolve(eq1,eq2,eq3,eq4);
conA1 = 'x1(0) = 0';
conA2 = 'x2(0) = 0';
conA3 = 'x1(2) = 5';
conA4 = 'x2(2) = 2';
sol_a = dsolve(eq1,eq2,eq3,eq4,conA1,conA2,conA3,conA4);
figure
ezplot(sol_a.x1,[0 2]); %x1
hold on
ezplot(sol_a.x2,[0,2]); %x2
ezplot(-sol_a.p2,[0,2]); %controllo
axis([0 2 -1 7])
legend('x1','x2','u')
Thanks to anyone who will pay some attention to my problem.

Akzeptierte Antwort

Torsten
Torsten am 10 Mai 2022
Bearbeitet: Torsten am 10 Mai 2022
I think this part
% convert symbolic objects to strings for using ’dsolve’
eq1 = strcat('Dx1=',char(Dx1)); %concatena le stringhe
eq2 = strcat('Dx2=',char(Dx2));
eq3 = strcat('Dp1=',char(Dp1));
eq4 = strcat('Dp2=',char(Dp2));
sol_h = dsolve(eq1,eq2,eq3,eq4);
conA1 = 'x1(0) = 0';
conA2 = 'x2(0) = 0';
conA3 = 'x1(2) = 5';
conA4 = 'x2(2) = 2';
sol_a = dsolve(eq1,eq2,eq3,eq4,conA1,conA2,conA3,conA4);
is equivalent to
syms x1(t) x2(t) p1(t) p2(t)
eq1 = diff(x1,t) == x1*x2;
eq2 = diff(x2,t) == -p2-x2;
eq3 = diff(p1,t) == -p1*x2;
eq4 = diff(p2,t) == -p1*x1 + p2;
eq = [eq1,eq2,eq3,eq4];
conA1 = x1(0)==0;
conA2 = x2(0)==0;
conA3 = x1(2)==5;
conA4 = x2(2)==2;
con = [conA1,conA2,conA3,conA4];
sol_a = dsolve(eq,con)
Is MATLAB able to find a solution ?
I guess no because of the nonlinear terms.
But maybe you can check out "bvp4c" for a numerical solution.

Weitere Antworten (0)

Kategorien

Mehr zu Robust Control Toolbox 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!

Translated by