M 文件和Simulink 求解连续微分系统实例分析 Matlab 自带的一个S 函数源代码: D:\MATLAB7\toolbox\simulink\blocks\sfuntmpl 例1. 常微分方程(Lorenze 混沌系统): 112322331223,,,xb xx xxa xa xxx xc xx (1) 其中10,28,8/ 3arb。 (1) m 文件实现:文件名为exam1.m function exam1 x0=[0;0;1e-3]; [t,x]=ode45(@lorenzfun,[0,100],x0); figure(1) plot(t,x) figure(2) plot3(x(:,1),x(:,2),x(:,3)) %---------------------------------- function dx=lorenzfun(t,x) a=10;c=28;b=8/3; dx=zeros(3,1); dx(1)=-b*x(1)+x(2)*x(3); dx(2)=-a*x(2)+10*x(3); dx(3)=-x(1)*x(2)+c*x(2)-x(3); 01 02 03 04 05 06 07 08 09 01 0 0-3 0-2 0-1 001 02 03 04 05 001 02 03 04 05 0-2 0-1 001 02 0-3 0-2 0-1 001 02 03 0 (2) (I)Simulink 模块实现:(见lorenzblok) x1-8/3x1x2x328x2x1*x2x2x23Out22x21x1ScopeProduct1Product1sIntegrator21sIntegrator11sIntegrator28Gain4-8/3Gain310Gain2-10Gain1 其中三个积分模块的初始值设置与exam1 相同,仿真时长为100s。精度设置:Simulation--Configuration Parameters—Relative tolerance, 1e-3 改为1e-5(试试不作此修改的结果比较)。运行后双击示波器 scope 后可看到: 或在 matlab 命令窗口输入画图命令: >> plot(tout,yout) >>plot3(yout(:,2),yout(:,3),yout(:,1)) 6065707580859095100-30-20-1001020304050-20-1001020-40-200204001020304050 (II)Simulink 向量模块实现:(见lorenzevector) tTo Workspace1xTo WorkspaceScope1sIntegrator-8*u(1)/3+u(2)*u(3)Fcn2-10*u(2)+10*u(3)Fcn1-u(1)*u(2)+28*u(2)-u(3)FcnClock 画图语句:>>plot(t,x) >>plot3(x(:,1),x(:,2),x(:,3)) (3)Simulink 中 S 函数的实现:(见lorenzsfun 和 lorenzsystem.m) tTo Workspace1xTo WorkspaceScopelorenzsystemS-FunctionClock 例2. 常时滞微分方程: '11'212'32(1),(1)(0.2),( ),yy tyy tytyyt (2) (1) m 文件需调用dde23 来求解:(见exam2.m) function exam2 sol = dde23('exam1f',[1, 0.2],ones(3,1),[0, 5]); plot(sol.x,sol.y); title('Example 2') xlabel('time t'); ylabel('y(t)'); %-------...