필터 지우기
필터 지우기

Coding problem for optimal control

조회 수: 1 (최근 30일)
Redwood
Redwood 2016년 5월 31일
댓글: Tarekegn Dinku 2024년 1월 20일
Dear Matlab experts,
I have a coding for optimal control problem, and this is not working. I would like to know how to solve this problem. Thank you very much in advance.
Sincerely yours,
J1
function Bloc1
% State equations
syms x1 x2 p1 p2 u;
Dx1 = x2^2;
Dx2 = -x2 + u;
% Cost function inside the integral
syms g;
g = 0.5*u^0.5*x2^0.5;
% Hamiltonian
syms p1 p2 H;
H = g + p1*Dx1 + p2*Dx2;
% Costate equations
Dp1 = -diff(H,x1);
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));
eq2 = strcat('Dx2=',char(Dx2));
eq3 = strcat('Dp1=',char(Dp1));
eq4 = strcat('Dp2=',char(Dp2));
sol_h = dsolve(eq1,eq2,eq3,eq4);
%%use boundary conditions to determine the coefficients
% case a: (a) x1(0)=x2(0)=0; x1(2) = 5; x2(2) = 2;
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);
% plot both solutions
figure(1);
ezplot(sol_a.x1,[0 3]); hold on;
ezplot(sol_a.x2,[0 3]);
ezplot(-sol_a.p2,[0 3]); % plot the control: u=-p2
axis([0 3 -1.6 7]);
text(0.6,0.5,'x_1(t)');
text(0.4,2.5,'x_2(t)');
text(1.6,0.5,'u(t)');
xlabel('time');
ylabel('states');
title('Solutions comparison (case a)');
  댓글 수: 2
Walter Roberson
Walter Roberson 2016년 5월 31일
Please give more details about the problems you are observing. Are you getting an error message? If not then what is the first output that does not match what you expect?
Tarekegn Dinku
Tarekegn Dinku 2024년 1월 20일
I want to your intial guess to control u

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Robust Control Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by