资源简介
Optimal control problems with fixed-final-
time
Optimal control problems with free-final-
time
代码片段和文件信息
function eg1OC
%EG1OC Example 1 of optimal control tutorial.
% This example is from D.E.Kirk‘s Optimal control theory: an introduction
% example 5.1-1 on page 198 - 202
% State equations
syms x1 x2 p1 p2 u;
Dx1 = x2;
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(Hx1);
Dp2 = -diff(Hx2);
% solve for control u
du = diff(Hu);
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(eq1eq2eq3eq4);
%% 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(eq1eq2eq3eq4conA1conA2conA3conA4);
% Compare the solutions from book and Matlab
sol_book = {@(t)(7.289*t-6.103+6.696*exp(-t)-0.593*exp(t))...
@(t)(7.289-6.696*exp(-t)-0.593*exp(t))};
time = linspace(0220);
s_book = [sol_book{1}(time); sol_book{2}(time)];
% plot both solutions
figure(1);
ezplot(sol_a.x1[0 2]); hold on;
ezplot(sol_a.x2[0 2]);
ezplot(-sol_a.p2[0 2]); % plot the control: u=-p2
plot(time s_book‘*‘);
axis([0 2 -1.6 7]);
text(0.60.5‘x_1(t)‘);
text(0.42.5‘x_2(t)‘);
text(1.60.5‘u(t)‘);
xlabel(‘time‘);
ylabel(‘states‘);
title(‘Solutions comparison (case a)‘);
hold off;
print -djpeg90 -r300 eg1a.jpg
%% --------------------------
% case b: (a) x1(0)=x2(0)=0; p1(2) = x1(2) - 5; p2(2) = x2(2) -2;
eq1b = char(subs(sol_h.x1‘t‘0));
eq2b = char(subs(sol_h.x2‘t‘0));
eq3b = strcat(char(subs(sol_h.p1‘t‘2))‘=‘char(subs(sol_h.x1‘t‘2))‘-5‘);
eq4b = strcat(char(subs(sol_h.p2‘t‘2))‘=‘char(subs(sol_h.x2‘t‘2))‘-2‘);
sol_b = solve(eq1beq2beq3beq4b);
% Substitute the coefficients
C1 = double(sol_b.C1);
C2 = double(sol_b.C2);
C3 = double(sol_b.C3);
C4 = double(sol_b.C4);
sol_b2 = struct(‘x1‘{subs(sol_h.x1)}‘x2‘{subs(sol_h.x2)}‘p1‘...
{subs(sol_h.p1)}‘p2‘{subs(sol_h.p2)});
% -----------------------------------------------
% plot the result
clear sol_book time s_book;
sol_book = {@(t)(2.697*t-2.422+2.560*exp(-t)-0.137*exp(t))...
@(t)(2.697-2.560*exp(-t)-0.137*exp(t))};
time = linspace(0220);
s_book = [sol_book{1}(time);sol_book{2}(time)];
figure(2);
ezplot(sol_b2.x1[0 2]); hold on;
ezplot(sol_b2.x2[0 2]);
ezplot(-sol_b2.p2[0 2]); % plot the control: u=-p2
plot(time s_book‘*‘);
axis([0 2 -.5 3]);
text(1.7‘x_1(t)‘);
text(0.41‘x_2(t)‘);
text(.22.5‘u(t)‘);
xlabel(‘time‘);
ylabel(‘states‘);
title(‘Solutions comparison (case b)‘);
hold off;
print -djpeg90 -r300 eg1b.jpg
%% ----------------
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4226 2009-11-10 12:54 An optimal control tutorial for beginners\eg1OC.m
文件 1614 2009-11-10 17:09 An optimal control tutorial for beginners\eg2OC_BVP.m
文件 3414 2009-11-09 03:32 An optimal control tutorial for beginners\eg2OC_Descent.m
文件 1133 2009-11-09 20:54 An optimal control tutorial for beginners\er3OC_num.m
文件 1113 2009-11-09 13:55 An optimal control tutorial for beginners\er3OC_num2.m
文件 1953 2009-11-09 11:34 An optimal control tutorial for beginners\er3OC_sym.m
文件 2213 2009-11-09 20:53 An optimal control tutorial for beginners\er4OC.m
文件 2013854 2009-11-16 00:25 An optimal control tutorial for beginners\Solving optimal control problems with MATLAB.pdf
目录 0 2011-07-06 15:08 An optimal control tutorial for beginners
----------- --------- ---------- ----- ----
2029520 9
相关资源
- 小波神经网络MAtlab工具箱
- Matlab UDP数据通讯工具箱用法
- Matlab中的YALMIP工具箱+教程
- Matlab求解偏微分方程工具箱使用举例
- MATLAB_LMI工具箱使用教程算例及论文原
- Max-flow/min-cut工具箱Bk_matlab
- 蚁群算法TSP问题工具箱
- MATLAB GA工具箱
- MDP方法工具箱MATLAB
-
xm
l和matlab格式相互转换工具箱 - matlab神经网络工具箱实现的数字分类
- matlab FastICA工具箱111010
- zw_Matlab工具箱调用SVM算法.zip
- MATLAB数字信号处理工具箱
- matlab可用粒子群工具箱 - PSOt
- matlab资源——NIT工具箱
- Numerical Methods with MATLAB(NMM1[1].5计算方
- HMM工具箱,隐马尔可夫matlab工具
- Matlab中LMI(线性矩阵不等式)工具箱
- l1-Magic工具箱
- 数据降维工具箱
- contourlet matlab 工具箱
- fastica工具箱
- matlab遗传算法geneticbx工具箱和安装步
- PSO工具箱
- l1-magic工具箱代码
- matlab通信工具箱教程
- 光镊计算工具箱
- prony 工具箱in matlab
- Matlab高阶统计量工具箱
评论
共有 条评论