MATLAB练习题和答案.doc_第1页
MATLAB练习题和答案.doc_第2页
MATLAB练习题和答案.doc_第3页
MATLAB练习题和答案.doc_第4页
MATLAB练习题和答案.doc_第5页
已阅读5页,还剩25页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

控制系统仿真实验Matlab部分实验结果目 录实验一 MATLAB基本操作1实验二 Matlab编程5实验三 Matlab底层图形控制6实验四 控制系统古典分析12实验五 控制系统现代分析15实验六 PID控制器的设计19实验七 系统状态空间设计23实验九 直流双闭环调速系统仿真25实验一 MATLAB基本操作1 用MATLAB可以识别的格式输入下面两个矩阵 再求出它们的乘积矩阵C,并将C矩阵的右下角23子矩阵赋给D矩阵。赋值完成后,调用相应的命令查看MATLAB工作空间的占用情况。A=1,2,3,3;2,3,5,7;1,3,5,7;3,2,3,9;1,8,9,4;B=1+4i,4,3,6,7,8;2,3,3,5,5,4+2i;2,6+7i,5,3,4,2;1,8,9,5,4,3;C=A*B;D=C(4:5,4:6);whos Name Size Bytes Class Attributes A 5x4 160 double B 4x6 384 double complex C 5x6 480 double complex D 2x3 96 double complex 2 选择合适的步距绘制出下面的图形,其中t=-1:0.1:1;y=sin(1./t);plot(t,y)3 对下面给出的各个矩阵求取矩阵的行列式、秩、特征多项式、范数、特征根、特征向量和逆矩阵。,A=7.5,3.5,0,0;8,33,4.1,0;0,9,103,-1.5;0,0,3.7,19.3;B=5,7,6,5;7,10,8,7;6,8,10,9;5,7,9,10;C=1:4;5:8;9:12;13:1rtf6;D=3,-3,-2,4;5,-5,1,8;11,8,5,-7;5,-1,-3,-1;det(A);det(B);det(C);det(D);rank(A);rank(B);rank(C);rank(D);a=poly(A);b=poly(B);c=poly(C);d=poly(D);norm(A);norm(B);norm(C);norm(D);v,d=eig(A,nobalance);v,d=eig(B,nobalance);v,d=eig(C,nobalance);v,d=eig(D,nobalance);m=inv(A);n=inv(B);p=inv(C);q=inv(D);4 求解下面的线性代数方程,并验证得出的解真正满足原方程。(a) ,(b)(a)A=7,2,1,-2;9,15,3,-2;-2,-2,11,5;1,3,2,13;B=4;7;-1;0;X=AB;C=A*X;(b)A=1,3,2,13;7,2,1,-2;9,15,3,-2;-2,-2,11,5;B=9,0;6,4;11,7;-2,-1;X=AB;C=A*X;5. (1) 初始化一10*10矩阵,其元素均为1ones(10,10); (2) 初始化一10*10矩阵,其元素均为0zeros(10,10); (3) 初始化一10*10对角矩阵v=1:10;diag(v); (4) 输入A=7 1 5;2 5 6;3 1 5,B=1 1 1; 2 2 2; 3 3 3,执行下列命令,理解其含义A(2, 3) 表示取A矩阵第2行、第3列的元素;A(:,2)表示取A矩阵的第列全部元素;A(3,:) 表示取A矩阵第行的全部元素;A(:,1:2:3)表示取A矩阵第1、3列的全部元素; A(:,3).*B(:,2)表示A矩阵第3列的元素点乘B矩阵第2列的元素 A(:,3)*B(2,:)表示A矩阵第3列的元素乘以B矩阵第2行A*B 矩阵AB相乘A.*B矩阵A点乘矩阵B A2矩阵A的平方 A.2矩阵表示求矩阵A的每一个元素的平方值 B/A 表示方程AX=B的解XB./A表示矩阵B的每一个元素点除矩阵A的元素6在同一坐标系中绘制余弦曲线y=cos(t-0.25)和正弦曲线y=sin(t-0.5),t0,2,用不同颜色,不同线的类型予以表示,注意坐标轴的比例控制。t=0:0.01:2*pi;y1=cos(t-0.25);plot(t,y1,r-)hold ony2=sin(t-0.5);plot(t,y2,k) 实验二 Matlab编程1分别用for和while循环结构编写程序,求出并考虑一种避免循环的简洁方法来进行求和。(a)j=1;n=0;sum=1; for n=n+1:63 for i=1:n j=j*2; end sum=sum+j; j=1;endsum(b)j=1;n=1;sum=1; while n=64 i=1; while in+1 j=j*2; i=i+1; end n=n+1; sum=sum+j; j=1;endSum(c)i=0:63;k=sum(2.i);2计算 1+2+n2000 时的最大 n 值s=0;m=0;while(s=2000),m=m+1;s=s+m;end,m3 用MATLAB语言实现下面的分段函数存放于文件ff.m中,令D=3,h=1求出,f(-1.5), f(0.5), f(5).D=3;h=1;x=-2*D:1/2:2*D;y=-h*(x=-D)&(xD);plot(x,y);grid onf1=y(find(x=-1.5)f2=y(find(x=0.5)f3=y(find(x=5)实验三 Matlab底层图形控制1 在MATLAB命令行中编程得到y=sin(t)和y1=cos(t)函数, plot(t,y);figure(10);plot(t,y1); t=-pi:0.05:pi; y=sin(t); y1=cos(t); plot(t,y) figure(10); plot(t,y1)2 在MATLAB命令行中键入h=get(0),查看根屏幕的属性,h此时为根屏幕句柄的符号表示,0为根屏幕对应的标号。 h=get(0)h = BeingDeleted: off BusyAction: queue ButtonDownFcn: CallbackObject: Children: 2x1 double Clipping: on CommandWindowSize: 89 27 CreateFcn: CurrentFigure: 1 DeleteFcn: Diary: off DiaryFile: diary Echo: off FixedWidthFontName: Courier New Format: short FormatSpacing: loose HandleVisibility: on HitTest: on Interruptible: on Language: zh_cn.gbk MonitorPositions: 1 1 1440 900 More: off Parent: PointerLocation: 1048 463 PointerWindow: 0 RecursionLimit: 500 ScreenDepth: 32 ScreenPixelsPerInch: 96 ScreenSize: 1 1 1440 900 Selected: off SelectionHighlight: on ShowHiddenHandles: off Tag: Type: root UIContextMenu: Units: pixels UserData: Visible: on3 h1=get(1);h2=get(10), 1, 10分别为两图形窗口对应标号,其中1为Matlab自动分配,标号10已在figure(10)中指定。查看h1和h2属性,注意CurrentAxes和CurrenObject属性。 h1=get(1)h1 = Alphamap: 1x64 double BeingDeleted: off BusyAction: queue ButtonDownFcn: Children: 170.0012 Clipping: on CloseRequestFcn: closereq Color: 0.8000 0.8000 0.8000 Colormap: 64x3 double CreateFcn: CurrentAxes: 170.0012 CurrentCharacter: CurrentObject: CurrentPoint: 0 0 DeleteFcn: DockControls: on FileName: FixedColors: 10x3 double HandleVisibility: on HitTest: on IntegerHandle: on Interruptible: on InvertHardcopy: on KeyPressFcn: KeyReleaseFcn: MenuBar: figure MinColormap: 64 Name: NextPlot: add NumberTitle: on PaperOrientation: portrait PaperPosition: 0.6345 6.3452 20.3046 15.2284 PaperPositionMode: manual PaperSize: 20.9840 29.6774 PaperType: A4 PaperUnits: centimeters Parent: 0 Pointer: arrow PointerShapeCData: 16x16 double PointerShapeHotSpot: 1 1 Position: 440 378 560 420 Renderer: painters RendererMode: auto Resize: on ResizeFcn: Selected: off SelectionHighlight: on SelectionType: normal Tag: ToolBar: auto Type: figure UIContextMenu: Units: pixels UserData: Visible: on WindowButtonDownFcn: WindowButtonMotionFcn: WindowButtonUpFcn: WindowKeyPressFcn: WindowKeyReleaseFcn: WindowScrollWheelFcn: WindowStyle: normal WVisual: 00 (RGB 32 GDI, Bitmap, Window) WVisualMode: auto h2=get(10)h2 = Alphamap: 1x64 double BeingDeleted: off BusyAction: queue ButtonDownFcn: Children: 342.0011 Clipping: on CloseRequestFcn: closereq Color: 0.8000 0.8000 0.8000 Colormap: 64x3 double CreateFcn: CurrentAxes: 342.0011 CurrentCharacter: CurrentObject: CurrentPoint: 0 0 DeleteFcn: DockControls: on FileName: FixedColors: 10x3 double HandleVisibility: on HitTest: on IntegerHandle: on Interruptible: on InvertHardcopy: on KeyPressFcn: KeyReleaseFcn: MenuBar: figure MinColormap: 64 Name: NextPlot: add NumberTitle: on PaperOrientation: portrait PaperPosition: 0.6345 6.3452 20.3046 15.2284 PaperPositionMode: manual PaperSize: 20.9840 29.6774 PaperType: A4 PaperUnits: centimeters Parent: 0 Pointer: arrow PointerShapeCData: 16x16 double PointerShapeHotSpot: 1 1 Position: 440 378 560 420 Renderer: painters RendererMode: auto Resize: on ResizeFcn: Selected: off SelectionHighlight: on SelectionType: normal Tag: ToolBar: auto Type: figure UIContextMenu: Units: pixels UserData: Visible: on WindowButtonDownFcn: WindowButtonMotionFcn: WindowButtonUpFcn: WindowKeyPressFcn: WindowKeyReleaseFcn: WindowScrollWheelFcn: WindowStyle: normal WVisual: 00 (RGB 32 GDI, Bitmap, Window) WVisualMode: auto4 输入h.Children,观察结果。 h.Childrenans = 1 105 键入gcf,得到当前图像句柄的值,分析其结果与h,h1,h2中哪个一致,为什么?ans = 1结果与h的一致6 鼠标点击Figure 1窗口,让其位于前端,在命令行中键入gcf,观察此时的值,和上一步中有何不同,为什么?ans = 17 观察h1.Children和h2.Children,gca的值。 h1.Childrenans = 170.0012 h2.Childrenans = 342.0011 gcaans = 170.00128 观察以下程序结果h3=h1.Children; set(h3,Color,green);h3_1=get(h3,children);set(h3_1, Color,red); 其中h3_1为Figure1中线对象句柄,不能直接采用h3_1=h3.Children命令获得。9 命令行中键入plot(t,sin(t-pi/3),观察曲线出现在哪个窗口。h4=h2.Children;axes(h4); plot(t,sin(t-pi/3),看看此时曲线显示在何窗口。plot(t,sin(t-pi/3)后,曲线出现在figure1窗口;h4=h2.Children;axes(h4); plot(t,sin(t-pi/3)后,曲线出现在figure10实验四 控制系统古典分析3已知二阶系统(1) 编写程序求解系统的阶跃响应;a=sqrt(10);zeta=(1/a);num=10;den=1 2*zeta*a 10;sys=tf(num,den);t=0:0.01:3;figure(1)step(sys,t);grid修改参数,实现和的阶跃响应;时:a=sqrt(10);zeta=1;num=10;den=1 2*zeta*a 10;sys=tf(num,den);t=0:0.01:3;figure(1)step(sys,t);grid时:a=sqrt(10);zeta=2;num=10;den=1 2*zeta*a 10;sys=tf(num,den);t=0:0.01:3;figure(1)step(sys,t);grid修改参数,实现和的阶跃响应()时:a=sqrt(10);zeta=(1/a);num=0.25;den=1 2*zeta*0.5*a 0.25;sys=tf(num,den);t=0:0.01:3;figure(1)step(sys,t);grid时:a=sqrt(10);zeta=(1/a);num=40;den=1 2*zeta*2*a 40;sys=tf(num,den);t=0:0.01:3;figure(1)step(sys,t);grid(2) 试做出以下系统的阶跃响应,并比较与原系统响应曲线的差别与特点,作出相应的实验分析结果。 ; 要求:分析系统的阻尼比和无阻尼振荡频率对系统阶跃响应的影响; 分析响应曲线的零初值、非零初值与系统模型的关系;分析响应曲线的稳态值与系统模型的关系;分析系统零点对阶跃响应的影响;a=sqrt(10);zeta=(1/a);num=10;den=1 2*zeta*a 10;sys=tf(num,den);t=0:0.01:3;step(sys,t);hold onnum1=0 2 10;sys1=tf(num1,den);step(sys1,t); num2=1 0.5 10;sys2=tf(num2,den);step(sys2,t); num3=1 0.5 0;sys3=tf(num3,den);step(sys3,t); num4=0 1 0;sys4=tf(num4,den);step(sys4,t);grid5 已知令k1作Bode图,应用频域稳定判据确定系统的稳定性,并确定使系统获得最大相位裕度的增益k值。G=tf(1 1,0.1 1 0 0 );figure(1)margin(G);grid实验五 控制系统现代分析1(2)Bode 图法判断系统稳定性: 已知两个单位负反馈系统的开环传递函数分别为: 用 Bode 图法判断系统闭环的稳定性。G1=tf(2.7,1 5 4 0 );figure(1)margin(G);gridG2=tf(2.7,1 5 -4 0 );figure(2)margin(G2);grid2系统能控性、能观性分析已知连续系统的传递函数模型:当分别取1,0,1 时,判别系统的能控性与能观性。当取-1时:num=1 -1;den=1 10 27 18;G=tf(num,den);G1=ss(G)a=-10 -3.375 -2.25; 8 0 0;0 1 0;b=0.5;0;0;Uc=b,a*b,a2*b;rank(Uc) a = x1 x2 x3 x1 -10 -3.375 -2.25 x2 8 0 0 x3 0 1 0 b = u1 x1 0.5 x2 0 x3 0 c = x1 x2 x3 y1 0 0.25 -0.25 d = u1 y1 0 Continuous-time model.rankUc = 3rankUo = 3由此,可以得到系统能控性矩阵Uc的秩是3,等于系统的维数,故系统是能控的。能观性矩阵Uo的秩是3,等于系统的维数,故系统能观测的。当取0时:a = x1 x2 x3 x1 -10 -3.375 -2.25 x2 8 0 0 x3 0 1 0 b = u1 x1 0.25 x2 0 x3 0 c = x1 x2 x3 y1 0 0.5 0 d = u1 y1 0 Continuous-time model.rankUc = 3rankUo = 3由此,可以得到系统能控性矩阵Uc的秩是3,等于系统的维数,故系统是能控的。能观性矩阵Uo的秩是3,等于系统的维数,故系统能观测的。当取1时:a = x1 x2 x3 x1 -10 -3.375 -2.25 x2 8 0 0 x3 0 1 0 b = u1 x1 0.5 x2 0 x3 0 c = x1 x2 x3 y1 0 0.25 0.25 d = u1 y1 0rankUc = 3rankUo = 2由此,可以得到系统能控性矩阵Uc的秩是3,等于系统的维数,故系统是能控的。能观性矩阵Uo的秩是2,小于系统的维数,故系统不能观测的。实验六 PID控制器的设计1已知三阶对象模型,利用MATLAB编写程序,研究闭环系统在不同控制情况下的阶跃响应,并分析结果。(1) 时,在不同KP值下,闭环系统的阶跃响应;s=tf(s);G=1/(s+1)3;for K=0:0.5:2;hold onstep(feedback(G*K,1)end 比例环节:成比例地反映控制系统的偏差信号e( t) , 偏差一旦产生, 控制器立即产生控制作用,以减小偏差。比例系数越大,误差越小。(2) 时,在不同值下,闭环系统的阶跃响应;s=tf(s);G=1/(s+1)3;for Ti=1:0.5:3;hold on G1=1+tf(1,Ti,0);step(feedback(G*G1,1)end积分环节:主要用于消除静差,提高系统的无差度。积分作用的强弱取决于积分时间常数TI ,TI越大,积分作用越弱,反之则越强。(3) 时,在不同值下,闭环系统的阶跃响应;s=tf(s);G=1/(s+1)3;for Td=1:0.5:3;hold on G1=1+tf(1,1,0)+tf(Td 0,Td/10 1);step(feedback(G*G1,1)end微分环节:反映偏差信号的变化趋势(变化速率) ,并能在偏差信号变得太大之前, 在系统中引入一个有效的早期修正信号, 从而加快系统的动作速度,减少调节时间。2 被控对象同上,选择合适的参数进行模拟PID控制(PID参数整定)s=tf(s);G=1/(s+1)3;K1,L1,T1,G1=getfolpd(1,G);G1N=10;K=1.014;T=2.101;L=1.1;a=K*L/T;Kp=1.2/a,Ti=2*L,Td=0.5*L,G2=Kp*(1+tf(1,Ti,0)+tf(Td 0,Td/N 1);step(sys1=feedback(G*G2,1);gridhold onstep(feedback(G,1)实验七 系统状态空间设计3已知对象模型(1) 如果我们想将闭环系统的极点配置到-1,-2,-3,利用MATLAB设计控制器,并绘出闭环系统的阶跃响应曲线。(说明:用两种方法配置极点)采用Ackermann公式计算:A=-0.3 0.1 -0.05;1 0.1 0;-1.5 -8.9 -0.05;B=2;0;4;C=1 2 3;D=0;P=-1 -2 -3;k=acker(A,B,P)Ac=A-B*keig(Ac)G=ss(Ac,B,C,D)G1=tf(G)t=0:0.01:3;step(G1,t);grid采用鲁棒极点配置算法:A=-0.3 0.1 -0.05;1 0.1 0;-1.5 -8.9 -0.05;B=2;0;4;C=1 2 3;D=0;P=-1 -2 -3;k=place(A,B,P)Ac=A-B*keig(Ac)

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论