文档详情

机电系统计算机仿真.docx

发布:2016-12-16约2.79千字共9页下载文档
文本预览下载声明
机电系统计算机仿真写出用Matlab建立传递函数为系统的模型的函数实现语句程序: num=[1,3];den=[1,1,1,4];G=tf(num,den) Transfer function: s + 3-----------------s^3 + s^2 + s + 42.设系统的微分方程为式中,y为输出变量;u为输入变量。试求系统的状态方程,并用Matlab建立状态方程。状态方程:程序: A=[0 1 0;0 0 1;-11 -7 -5;];B=[0 0 6];C=[1 0 0];D=0;G=ss(A,B,C,D) a = x1 x2 x3 x1 0 1 0 x2 00 1 x3 -11 -7 -5 b = u1 x1 0 x2 0 x3 6c = x1 x2 x3 y1 1 00 d = u1 y1 0 Continuous-time model.3.用欧拉法求解初值问题,,取步长h=0.1,计算y(0.2)时的近似值。M函数:function [ tout,yout ] =euler( odefile,tspan,y0,h)ts=tspan;t0=ts(1);tf=ts(2);h=h(:);yout=[],tout=[];y0=y0(:);for t=[t0:h:tf]y0=y0+h*feval(odefile,t,y0);yout=[yout;y0];tout=[tout;t];end主函数: f=@(t,x)[x(2);-2*x(2)+3*x(1)];x0=[1;0];h=0.1;tspan=[0 2];[t,x]=euler(f,tspan,x0,h)t = 0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000 1.1000 1.2000 1.3000 1.4000 1.5000 1.6000 1.7000 1.8000 1.9000 2.0000x = 1.0000 0.3000 1.0300 0.5400 1.0840 0.7410 1.1581 0.9180 1.2499 1.0818 1.3581 1.2404 1.4821 1.3998 1.6221 1.5645 1.7785 1.7382 1.9524 1.9241 2.1448 2.1250 2.3573 2.3434 2.5916 2.5819 2.8498 2.8430 3.1341 3.1294 3.4471 3.4437 3.7914 3.7891 4.1703 4.1687 4.5872 4.5861 5.0458 5.0450 5.5503 5.5498y(0.2)时的近似值为1.0840 plot(t,x),grid4.用欧拉预估—校正法求下列初值问题的数值解其中0x1, 取h=0.2,计算y(0.4)时的近似值。M函数:function [ tout,yout ] =eulerbetter( odefile,tspan,y0,h)ts=tspan;t0=ts(1);tf=ts(2);h=h(:);yout=[],tout=[];y0=y0(:);for t=[t0:h:tf]k1=feval(odefile,t,y0);k2=feval(odefile,t+h,y0+h*k1);yout=[yout;y0];tout=[tout;t];y0=y0+h/2*(k1+k2);end主函数: f=@(t,x)t^2+t-x(1);x0=1;h=0.2;tspan=[0 1];[t,x]=eulerbetter(f,tspan,x0,h)t = 0 0.2000 0.4000 0.6000 0.8000 1.0000x = 1.0000 0.8440 0.7673 0.7700 0.85221.0140可以得出y(0.4)时的近似值为0.7673状态变量的时间响应图5. 有初始状态为0的二阶微分方程,其中是单位阶跃函数,试用龙格库塔法求解t=0.02时的数值解,步长取为h=0.1。并用Matlab编写仿真程序计算数值解。M函数:function [ tout,yout ] =rk_4( odefile,tspan,y0,h)ts=tspan;t0=ts(1);tf=ts(2);h=h(:);yout=[],tout=[];y0=y0(:);for t=[t0:h:tf]k1=h*feval(odefile,t,y0);k2=h*feval(odefile,t+h/2,y0+0.
显示全部
相似文档