飞行器系统仿真
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
《飞行器系统仿真与C A D》学习报告
第一部分仿真(40)
题目1:给定导弹相对于目标的运动学方程组为
r(0) = 5km, q(0) = 60deg, (0) = 30deg,V = , V m= , 1Ma = 340m/s, k = 2 (1)建立系统的方框图模型;
(2)用MATLAB语言编写S—函数
(3)用窗口菜单对(1), (2)进行仿真,动态显示结果;
(4)用命令行对(1), (2)进行仿真,以图形显示结果
答:
(1)
(2)用MATLAB语言编写S函数
function [sys,x0,str,ts]=CAD1_sfun(t,x,u,flag)
switch flag
case 0
[sys,x0,str,ts]=mdlInitializeSizes;
case 1
sys = mdlDerivatives(t,x,u);
case 3
sys = mdlOutputs(t,x,u);
case {2,4,9}
sys = [];
otherwise
error('unhandled flag=',num2str(flag))
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes=simsizes;
=3;
=0;
=3;
=0; =1; =1;
sys=simsizes(sizes); str=[];
x0=[5000,pi/3,pi/6]; ts=[0 0];
function sys=mdlDerivatives(t,x,u) vm=*340; v=*340; k=2;
dx(1)=vm*cos(x(2))-v*cos(x(2)-x(3));
dx(2)=(v*sin(x(2)-x(3))-vm*sin(x(2)))/x(1); dx(3)=k*dx(2); sys=dx;
function sys=mdlOutputs(t,x,u) sys=x;
调用S 函数的模型框图 (3)框图仿真结果: S 函数仿真结果: (4)命令输入
clear;clc
[t x ] = sim('CAD1'); hSimulink = figure(); subplot(3, 1, 1);
plot(t,x(:,1)); grid; ylabel('r'); subplot(3, 1, 2);
plot(t,x(:,2)); grid; ylabel('q'); subplot(3, 1, 3);
plot(t,x(:,3)); grid; ylabel('sigma'); [t x ] = sim('CAD1_S'); hSFun = figure(); subplot(3, 1, 1);
plot(t,x(:,1)); grid; ylabel('r'); subplot(3, 1, 2);
plot(t,x(:,2)); grid; ylabel('q'); subplot(3, 1, 3);
plot(t,x(:,3)); grid; ylabel('sigma'); 模型仿真结果: S 函数仿真结果:
题目2:给出动态方程
0)0(,1)0(;1)1(2
===+-+⋅
⋅
⋅
⋅x x tx x x x ;
(1) 用MATLAB 语言编写S —函数;
(2) 用命令行gear/adams 法对(1)进行仿真,显示曲线x(t=0:100); (3) 建立方框图,用RK45仿真50秒,显示曲线
答:
(1)用MATLAB语言编写S—函数
function[sys,x0,str,ts]=CAD2_sfu n(t,x,u,flag)
switch flag
case 0
[sys,x0,str,ts]=mdlInitializeSiz es;
case 1
sys=mdlDerivatives(t,x,u);
case 3
sys=mdlOutputs(t,x,u);
case {2,4,9}
sys=[];
otherwise
error('unhandled
flag=',num2str(flag))
end
function
[sys,x0,str,ts]=mdlInitializeSiz es sizes=simsizes;
=2;
=0;
=2;
=0;
=1;
=1;
sys=simsizes(sizes);
str=[];
x0=[1,0];
ts=[0 0];
function
sys=mdlDerivatives(t,x,u)
dx(1)=x(2);
dx(2)=1-t*x(1)-(1-x(1)^2)*x(2); sys=dx;
function sys=mdlOutputs(t,x,u) sys=x;
(2)直接调用ode数值积分函数进行仿真,系统微分方程:
function dx = CAD01_02odefun(t, x)
dx(1) = x(2);
dx(2) = 1-(1-x(1)*x(1))*x(2) - t*x(1);
dx = dx';
调用ode解算器入口:
clear; clc;
[t x] = ode15s(@CAD01_02odefun, 0:100, [1 0]);
hGear = figure();
set(hGear, 'NumberTitle', 'off', 'Name', 'Integrated by the Gear algorithm', 'Units', 'Normalized', 'Position', [ ]);
subplot(2, 1, 1);
plot(t, x(:,1)); grid; ylabel('x');
subplot(2, 1, 2);
plot(t, x(:,2)); grid; ylabel('dx/dt');
[t x] = ode113(@CAD01_02odefun, 0:100, [1 0]);
hAdams = figure();
set(hAdams, 'NumberTitle', 'off', 'Name', 'Integrated by the Adams algorithm', 'Units', 'Normalized', 'Position', [ ]);
subplot(2, 1, 1);
plot(t, x(:,1)); grid; ylabel('x');
subplot(2, 1, 2);