《量化投资:以MATLAB为工具》

MATLAB技术论坛

 找回密码
 注册账号
查看: 282|回复: 0
收起左侧

[提问] PID控制中ode45 解方程问题

[复制链接]
发表于 2018-9-15 11:07:00 | 显示全部楼层 |阅读模式
%Discrete PID control for continuous plant
clear all;
close all;

ts=0.001;  %Sampling time
xk=zeros(2,1);
e_1=0;
u_1=0;

for k=1:1:2000
time(k) = k*ts;

yd(k)=0.50*sin(1*2*pi*k*ts);
  
para=u_1;
tSpan=[0 ts];
%tSpan=[k*ts (k+1)*ts];
[tt,xx]=ode45('chap1_6plant',tSpan,xk,[],para);
xk = xx(length(xx),:);
y(k)=xk(1);

e(k)=yd(k)-y(k);
de(k)=(e(k)-e_1)/ts;

u(k)=20.0*e(k)+0.50*de(k);
%Control limit
if u(k)>10.0
   u(k)=10.0;
end
if u(k)<-10.0
   u(k)=-10.0;
end

u_1=u(k);
e_1=e(k);
end
figure(1);
plot(time,yd,'r',time,y,'k:','linewidth',2);
xlabel('time(s)');ylabel('yd,y');
legend('Ideal position signal','Position tracking');
figure(2);
plot(time,yd-y,'r','linewidth',2);
xlabel('time(s)'),ylabel('error');

chap1_6plant 函数:
function dy = PlantModel(t,y,flag,para)
u=para;
J=0.0067;B=0.1;

dy=zeros(2,1);
dy(1) = y(2);
dy(2) = -(B/J)*y(2) + (1/J)*u;


为什么ode45('chap1_6plant',tSpan,xk,[],para)这么写?正常的调用格式ode45('chap1_6plant',tSpan,xk)就不能运行
您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

QQ|网站地图|MATLAB技术论坛|Simulink仿真论坛 ( 蜀ICP备19014457号 

GMT+8, 2020-2-28 06:49 , Processed in 0.053141 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表