1、学号 专业名称 姓名 学号班号南京林业大学研究生试卷题号一二三四五六七八九十总 分得分课程号 33351 课程名称 计算机仿真 20 16 20 17 学年第 1 学期一、(20分)某系统的传递函数为试用级联法、串联法和并联法中的两种画出系统模拟结构图,并列出相应的状态方程和输出方程。自拟仿真,比较两者结果。 答:选用级联法和并联法写出传递函数,公式如下: 分别画出级联法、并联法的系统模拟结构图及其状态方程和输出方程,图式如下:状态方程:输出方程:状态方程:输出方程:使用龙格-库塔法程序进行仿真,令u=1,系统在t=02s之间(仿真步长0。1s)则输出y截图如下: 比较后发现两者仿真结果接近.
2、二、(20分)已知系统的状态方程及输出方程 拟用四阶龙格库塔法求系统在t=0-2s之间的输出值(仿真步长取0。01s或0。1s),试编写仿真程序,对仿真结果截图.(单号C+,双号VB)答:用c+进行四阶龙格库塔法,系统在t=0-2s间的(仿真步长0.01)编程:includeusing namespace std;float x1;float x2;float x3;float x4;float t;float f1(float x1,float x2,float x3,float x4,float t)float f1;return f1=3x1+2*x2x3;float f2(float
3、x1,float x2,float x3,float x4,float t)float f2;return f2=2*x1x2+2*x3;float f3(float x1,float x2,float x3,float x4,float t)float f3;return f3=x1+2x2-x3+2;float f4(float x1,float x2,float x3,float x4,float t)float f4;return f4=0;int main()float k11,k12,k13,k14,k21,k22,k23,k24,k31,k32,k33,k34,k41,k42,k
4、43,k44;float t=0,h=0.01;double y;float x1=0,x2=0,x3=0,x4=0;for(int i=1;i200;i+)t=t+h;k11 = h * f1(x1, x2, x3, x4, t); k21 = h * f2(x1, x2, x3, x4, t); k31 = h f3(x1, x2, x3, x4, t); k41 = h f4(x1, x2, x3, x4, t); k12 = h * f1(x1 + k11 / 2, x2 + k21 / 2, x3 + k31 / 2, x4 + k41 / 2, t + h / 2); k22 =
5、h f2(x1 + k11 / 2, x2 + k21 / 2, x3 + k31 / 2, x4 + k41 / 2, t + h / 2); k32 = h * f3(x1 + k11 / 2, x2 + k21 / 2, x3 + k31 / 2, x4 + k41 / 2, t + h / 2); k42 = h * f4(x1 + k11 / 2, x2 + k21 / 2, x3 + k31 / 2, x4 + k41 / 2, t + h / 2); k13 = h * f1(x1 + k12 / 2, x2 + k22 / 2, x3 + k32 / 2, x4 + k42 /
6、 2, t + h / 2); k23 = h * f2(x1 + k12 / 2, x2 + k22 / 2, x3 + k32 / 2, x4 + k42 / 2, t + h / 2); k33 = h f3(x1 + k12 / 2, x2 + k22 / 2, x3 + k32 / 2, x4 + k42 / 2, t + h / 2); k43 = h f4(x1 + k12 / 2, x2 + k22 / 2, x3 + k32 / 2, x4 + k42 / 2, t + h / 2); k14 = h * f1(x1 + k13, x2 + k23, x3 + k33, x4
7、 + k43, t + h); k24 = h f2(x1 + k13, x2 + k23, x3 + k33, x4 + k43, t + h); k34 = h * f3(x1 + k13, x2 + k23, x3 + k33, x4 + k43, t + h); k44 = h f4(x1 + k13, x2 + k23, x3 + k33, x4 + k43, t + h); x1 = x1 + (k11 + 2 k12 + 2 k13 + k14) / 6; x2 = x2 + (k21 + 2 * k22 + 2 * k23 + k24) / 6; x3 = x3 + (k31
8、+ 2 k32 + 2 k33 + k34) / 6;y=x1+2x2-2*x3;cout”y=yendl;return 0;仿真结果截图如下:三、(20分)已知单位反馈系统的开环传递函数为试用Z域离散相似法和时域离散相似法进行仿真,编写仿真程序,对仿真结果截图。(输出初态为0,输入为3,仿真步长为0.02S,100200个周期)(单号VB,双号C+)答:先将函数化成为:画出系统结构图:使用z域离散相似法计算得:仿真程序如下:Private Sub Command1_Click()Dim n As SingleDim t As SingleDim w(200) As SingleDim x(2
9、00) As SingleDim z(200) As SingleDim y(200) As SingleDim u(200) As Singlet = 0。02y(0) = 0For n = 0 To 199w(n + 1) = w(n) + t 3x(n + 1) = x(n) * Exp(4 t) + w(n + 1) w(n) (3 + Exp(-4 * t)) / 4y(n + 1) = y(n) Exp(3 t) + x(n) * 50 (1 - Exp(-3 t) / 3NextText1.Text = y(200)End Sub仿真结果截图如下:使用时域相似法计算得:仿真程序如
10、下:Private Sub Command1_Click()Dim w(2000) As SingleDim x(2000) As SingleDim y(2000) As SingleDim T As SingleDim n As SingleT = 0.02y(0) = 0For n = 0 To 199w(n + 1) = w(n) + T * 3x(n + 1) = x(n) Exp(-4 T) + (w(n) + 3) (0。25 0.25 Exp(4 T)y(n + 1) = Exp(-3 T) * y(n) + 50 x(n) (1 Exp(-3 * T) / 3NextText
11、1。Text = y(200)End Sub仿真结果截图如下:四、 (20分)投掷硬币实验,至少投掷多少次,才能使正面朝上的频率在0。40。6之间的概率不小于0。9 ?试编写仿真程序,对仿真结果截图。(仿真800012000次)答:(仿真12000次)程序如下:Private Sub Command1_Click()Dim a As SingleDim i As IntegerDim j As IntegerDim t As IntegerDim s As SingleFor j = 1 To 12000n = 0For i = 1 To 25r = Rnd()If r = 0.5 Thenn
12、 = n + 1End IfNextIf 0.4 = n / 25 = 0.6 Thenm = m + 1End IfIf m / 25 = 0。9 Thens = s + 1End IfNextText1。Text = sEnd Sub仿真结果截图如下:五、 (20分)某自选市场,平均每分钟有6位顾客到来,每位顾客购物时间服从(4.2,7.2)分钟均布(不包括交费时间)。有十个收银台,每位顾客服务时间服从(1。2,2)分钟均布.试用GPSS仿真其排队情况。要求画出仿真模型的程序块框图,列出程序清单,对仿真结果截图。(仿真40005000次) 答:程序清单及程序块框图如下: SIMULATE 1 STORAGE 10 GENERATE 1/6,0 ADVANCE 5。7,1.5 QUEUE 1 ENTER 1 DEPART 1 MARK ADVANCE 1。6,。4 LEAVE 1 TABULATE 1 TERMINATE 1 1 TABLEIA,5,5,10 START 4000 END