中南大学matlab试卷
- 格式:doc
- 大小:881.50 KB
- 文档页数:17
电子信息科学与技术09级Matlab期末考试试卷
(2012年5月)
院系: 物理与电子
年级: 电信09级
班级: 3班
学号:
1404090311 姓名: 徐云霄
题号 1 2 3 4 5 总成绩 评卷人
得分
说明:请保留题目,在每个题目解答部分的空白处依次作答,并写清楚每个小题的题号。作答要给出程序代码、仿真结果。
1、(30分) 如下图所示的弹簧振子系统在光滑的水平面运动,已知弹簧振子的质量kgm2.0,弹簧的倔强系数mNK/2.0。在0t时弹簧振子位于mx1)0(,速度为smv/2)0(。假设该系统在0t时受到沿正方向的策动力teF2.01.0的作用,并且弹簧所受空气等阻力为cvf阻,其中mNsc/1.0,v为弹簧振子的运动速度。因此,该运动方程可以表示为:tekxxcxm2.01.0。
(1) 利用Dsolve函数,编写程序代码求解弹簧振子运动方程的通解,并仿真st]20,0[弹簧振子的位置图像。(5分)
(2) 利用常微分方程的数值解法编写程序代码,利用子图绘制函数subplot(3,2,n)在同一窗口分别绘制st]20,0[弹簧振子:(10分)
(a) 位置图像(要求标注:线的颜色(红色)、线型(-.点划线)、线宽(2)、数据点标注形状(* ));(b) 速度图像;(c) 加速度图像;(d) 弹簧振子动能221mvEk图像;(e) 弹簧振子势能221kxEp图像;(f) 弹簧振子能量图像。以上绘图分别要求标注对应的标题(如:位置图像、速度图像……)。
(3) 构建simulink仿真模块,在同一个窗口利用三个坐标系按顺序分别仿真st]20,0[弹簧振子的加速度图像、速度图像、位置图像。(5分)
(4) 利用s-function,构建simulink仿真模块,在同一个窗口利用三个坐标系按顺序分别仿真st]20,0[弹簧振子的位置图像、速度图像、加速度图像。(s-function函数程序只需给出编写的主要代码)(10分)
x
0 解答:
(1) 第一小问:
syms x t
>> y=dsolve('0.2*D2x=-0.1*Dx-0.2*x+0.1*exp(-0.2*t)','t')
y =
exp(-1/4*t)*sin(1/4*15^(1/2)*t)*C2+exp(-1/4*t)*cos(1/4*15^(1/2)*t)*C1+25/47*exp(-1/5*t)
第二小问:
首先求解运动方程的特解
y=dsolve('0.2*D2x=-0.1*Dx-0.2*x+0.1*exp(-0.2*t)','x(0)=1','Dx(0)=-2','t')
y =
-334/705*exp(-1/4*t)*sin(1/4*15^(1/2)*t)*15^(1/2)+22/47*exp(-1/4*t)*cos(1/4*15^(1/2)*t)+25/47*exp(-1/5*t)
进行仿真
t=0:0.1:20;
y=-334/705*exp(-1/4*t).*sin(1/4*15.^(1/2)*t)*15^(1/2)+22/47*exp(-1/4*t).*cos(1/4*15^(1/2)*t)+25/47*exp(-1/5*t); %将求出的特解转化为矩阵形式。
>> plot(t,y,'r')
仿真之后的效果图如下
(2) 程序代码如下:
function xdot=sys(t,x)
xdot=[0.5*x(3)-0.75*x(2)-0.35*exp(-0.2*t);-0.5*x(2)-x(3)+0.5*exp(-0.2*t);x(2)];
t0=0;tf=20;
[t,x]=ode45('sys',[t0 tf],[1 -2 1]);
Ek=1/2*0.2*x(:,2).^2;
Ep=1/2*0.2*x(:,3).^2;
E=Ek+Ep;
subplot(231),plot(t,x(:,3),'-.r*'),title('位置图像');
subplot(232),plot(t,x(:,2),'-.r*'),title('速度图像');
subplot(233),plot(t,x(:,1),'-.r*'),title('加速度图像');
subplot(234),plot(t,Ek,'-.r*'),title('弹簧振子动能图像');
subplot(235),plot(t,Ep,'-.r*'),title('弹簧振子势能图像');
>> subplot(236),plot(t,E,'-.r*'),title('弹簧振子能量图像');
运行后的图像如下:
(3)构建simulink仿真模块如下图
仿真之后的结果如下图
从上之下依次为位置图像 ,速度图像,加速度图像。
(4)s-function函数程序的主要代码如下: sizes = simsizes;
sizes.NumContStates = 3;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
x0 = [1 -2 1];
str = [];
ts = [0 0];
function sys=mdlDerivatives(t,x,u)
sys = [0.5*x(3)-0.75*x(2)-0.35*u(1);-0.5*x(2)-x(3)+0.5*u(1);x(2)];
function sys=mdlUpdate(t,x,u)
sys = [];
function sys=mdlOutputs(t,x,u)
sys = [x(1);x(2);x(3)];
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampleTime = 1; % Example, set the next hit to be one second later.
sys = t + sampleTime;
function sys=mdlTerminate(t,x,u)
sys = [];
Simulink仿真模块如下:
运行结果如下:
2、(20分) 已知公元1年1月1日是星期一。制作如图所示界面并编写程序代码,点击显示按钮可实现如下功能:输入任何年月日,显示星期几(显示格式见界面)。(提示:能被4整除不能被100整除的就是闰年,能被400整除的年份也是闰年(整千年),反之就是平年。闰年2月29天,平年2月28天。)(函数程序只需给出编写的主要代码)。
解答:edit1程序
if str2num(get(handles.edit1,'string'))<=0
button=questdlg('输入的格式不正确!请重新输入','error','确定','确定')
switch button
case '确定',
set(handles.edit1,'string','')
end
end
edit2程序
if str2num(get(handles.edit2,'string'))<=0 |
str2num(get(handles.edit2,'string'))>12
button=questdlg('输入的格式不正确!请重新输入','error','确定','确定')
switch button
case '确定',
set(handles.edit2,'string','')
end
end
edit3程序
year=str2num(get(handles.edit1,'string'));
if rem(year,4)==0 & rem(year,100)~=0 | rem(year,400)==0 %如果是润年2月
switch str2num(get(handles.edit2,'string'))
case {2}
if str2num(get(handles.edit3,'string'))>29
button=questdlg('输入的格式不正确!请重新输入','error','确定','确定')
switch button
case '确定',
set(handles.edit3,'string','')
set(handles.edit4,'string','')
end % for switch
end % for if
case {1,3,5,7,8,10,12}
if str2num(get(handles.edit3,'string'))>31
button=questdlg('输入的格式不正确!请重新输入','error','确定','确定')
switch button