24小时热门版块排行榜    

查看: 928  |  回复: 0

jjliu2012

新虫 (小有名气)

[求助] 【求助 一个关于最优控制的matlab问题(新手,请大家多多帮助)

Sample Text
最速下降法求最优控制u的matlab算法,各位大侠能否把这个主循环补充一下,不知道怎么回事,运行不了 。是附件里文献的例子2,在第7页,多谢
%%%%%%%%%%%%%%%%%%%%%%
for i = 1:max_iteration
% 1) start with assumed control u and move forward
[Tx,X] = ode45(@(t,x) stateEq(t,x,u,Tu), [t0 tf], ...
initx, options);
% 2) Move backward to get the trajectory of costates
x1 = X(:,1); x2 = X(:,2);
[Tp,P] = ode45(@(t,p) costateEq(t,p,u,Tu,x1,x2,Tx), ...
[tf t0], initp, options);
p1 = P(:,1);
% Important: costate is stored in reverse order. The dimension of
% costates may also different from dimension of states
% Use interploate to make sure x and p is aligned along the time axis
p1 = interp1(Tp,p1,Tx);
% Calculate deltaH with x1(t), x2(t), p1(t), p2(t)
dH = pH(x1,p1,Tx,u,Tu);
H_Norm = dH'*dH;

% Calculate the cost function
J(i,1) = tf*(((x1')*x1 + (x2')*x2)/length(Tx) + ...
0.1*(u*u')/length(Tu));
% if dH/du < epslon, exit
if H_Norm < eps
% Display final cost
J(i,1)
break;
else
% adjust control for next iteration
u_old = u;
u = AdjControl(dH,Tx,u_old,Tu,step);
end;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% State equations
function dx = stateEq(t,x,u,Tu)
dx = zeros(2,1);
u = interp1(Tu,u,t); % Interploate the control at time t
dx(1) = -2*(x(1) + 0.25) + (x(2) + 0.5)*exp(25*x(1)/(x(1)+2)) ...
- (x(1) + 0.25).*u;
dx(2) = 0.5 - x(2) -(x(2) + 0.5)*exp(25*x(1)/(x(1)+2));
%%%%%%%%%%%%%%%%%%%%%%%
% Costate equations
function dp = costateEq(t,p,u,Tu,x1,x2,xt)
dp = zeros(2,1);
x1 = interp1(xt,x1,t); % Interploate the state varialbes
x2 = interp1(xt,x2,t);
u = interp1(Tu,u,t); % Interploate the control
dp(1) = p(1).*(u + exp((25*x1)/(x1 + 2)).*((25*x1)/(x1 + 2)^2 - ...
25/(x1 + 2))*(x2 + 1/2) + 2) - ...
2*x1 - p(2).*exp((25*x1)/(x1 + 2))*((25*x1)/(x1 + 2)^2 - ...
25/(x1 + 2))*(x2 + 1/2);
dp(2) = p(2).*(exp((25*x1)/(x1 + 2)) + 1) - ...
p(1).*exp((25*x1)/(x1 + 2)) - 2*x2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Partial derivative of H with respect to u
function dH = pH(x1,p1,tx,u,Tu)
% interploate the control
u = interp1(Tu,u,tx);
R = 0.1;
dH = 2*R*u - p1.*(x1 + 0.25);
%%%%%%%%%%%%%%%%%%%%%%%%%
% Adjust the control
function u_new = AdjControl(pH,tx,u,tu,step)
% interploate dH/du
pH = interp1(tx,pH,tu);
u_new = u - step*pH;
%%%%%%%%%%%%%%%%
回复此楼

» 本帖附件资源列表

  • 欢迎监督和反馈:小木虫仅提供交流平台,不对该内容负责。
    本内容由用户自主发布,如果其内容涉及到知识产权问题,其责任在于用户本人,如对版权有异议,请联系邮箱:xiaomuchong@tal.com
  • 附件 1 : SolvingoptimalcontrolproblemswithMATLAB.pdf
  • 2013-09-01 16:16:28, 1.95 M

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

智能机器人

Robot (super robot)

我们都爱小木虫

找到一些相关的精华帖子,希望有用哦~

科研从小木虫开始,人人为我,我为人人
相关版块跳转 我要订阅楼主 jjliu2012 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 321求调剂 +9 何润采123 2026-03-18 11/550 2026-03-20 23:19 by JourneyLucky
[考研] 南京大学化学376求调剂 +3 hisfailed 2026-03-19 3/150 2026-03-20 23:01 by 阿王see
[考研] 考研调剂求学校推荐 +3 伯乐29 2026-03-18 5/250 2026-03-20 22:59 by JourneyLucky
[考研] 323求调剂 +3 洼小桶 2026-03-18 3/150 2026-03-20 22:54 by JourneyLucky
[考研] 南昌大学材料专硕311分求调剂 +3 77chaselx 2026-03-20 3/150 2026-03-20 22:03 by luoyongfeng
[考研] 260求调剂 +3 朱芷琳 2026-03-20 3/150 2026-03-20 20:35 by 学员8dgXkO
[考研] 22408 344分 求调剂 一志愿 华电计算机技术 +3 solanXXX 2026-03-20 3/150 2026-03-20 16:41 by fxue1114
[考研] 265求调剂 +8 梁梁校校 2026-03-17 8/400 2026-03-20 14:40 by 27道科特
[考博] 招收博士1-2人 +3 QGZDSYS 2026-03-18 3/150 2026-03-20 11:58 by 呱呱呱呱叫
[考研] 320求调剂0856 +3 不想起名字112 2026-03-19 3/150 2026-03-19 22:53 by 学员8dgXkO
[考研] 一志愿985,本科211,0817化学工程与技术319求调剂 +10 Liwangman 2026-03-15 10/500 2026-03-19 10:25 by 无际的草原
[考研] 一志愿西南交大,求调剂 +4 材化逐梦人 2026-03-18 4/200 2026-03-18 14:22 by 007_lilei
[考研] 268求调剂 +8 一定有学上- 2026-03-14 9/450 2026-03-17 17:47 by laoshidan
[考研] 301求调剂 +4 A_JiXing 2026-03-16 4/200 2026-03-17 17:32 by ruiyingmiao
[硕博家园] 湖北工业大学 生命科学与健康学院-课题组招收2026级食品/生物方向硕士 +3 1喜春8 2026-03-17 5/250 2026-03-17 17:18 by ber川cool子
[考研] 290求调剂 +3 p asserby. 2026-03-15 4/200 2026-03-17 16:35 by wangkm
[论文投稿] 有没有大佬发小论文能带我个二作 +3 增锐漏人 2026-03-17 4/200 2026-03-17 09:26 by xs74101122
[考研] 283求调剂 +3 听风就是雨; 2026-03-16 3/150 2026-03-17 07:41 by 热情沙漠
[考研] 304求调剂 +4 ahbd 2026-03-14 4/200 2026-03-16 16:48 by 我的船我的海
[考研] 中科院材料273求调剂 +4 yzydy 2026-03-15 4/200 2026-03-16 15:59 by Gaodh_82
信息提示
请填处理意见