实验报告
课程名称: MATLAB Programming
实验项目: Position and Velocity of a Ball
专业班级: 通信工程1501班 姓 名: 刘文亚 学 号: 150404116 实验室号: 信息楼220 实验组号: 16 实验时间:2017年5月18日批阅时间: 指导教师: 刘笑楠 成 绩:
沈阳工业大学实验报告
(适用计算机程序设计类)
专业班级: 通信工程1501班 学号: 150404116 姓名: 刘文亚
实验名称:Position and Velocity of a Ball
1
1.实验目的: (1)Mastering methods for creating and initializing variables in MATLAB.including assignment statements, shortcut expressions,built-in functions,keyboard input. (2) Understand the difference between array multiplication and matrix multiplication. (3)Learn how to draw and icons, colors, etc. 2.实验内容: Position and Velocity of a Ball If a stationary ball is released at a height h0 above the surface of the Earth with a vertical velocity v0,the position and velocity of the ball as a function of time will be given by the equations Where g is the acceleration due to gravity(-9.81m/s^2),h is the height above the surface of the Earth(assuning no air friction),and v is the vertical component of velocity.Write a MATLAB program that prompts a user for the initial height of the ball in meter and velocity of the ball in meters per second,and plots the height and velocity as a function of time. Be sure to include proper labels in your plots. 3. 实验方案(程序设计说明)[包括算法设计思路,必要的流程图,界面设计说明、使用模块及变量的说明等。] (1)确定输入变量h0,v0,t1。h0是开始高度,v0是开始速度,t1为时间。 (2)由公式 计算在时间变化的情况2 下,h v的变化情况并得到多组数据 (3)由数据画出h,v与t的关系曲线 附件A 沈阳工业大学实验报告
(适用计算机程序设计类)
专业班级: 通信工程1501班 学号: 150404116 姓名: 刘文亚
实验步骤或程序:
(可加附页)
4. 实验步骤或程序(经调试后正确的源程序) (1)创建程序
%Script file:calc_height and velocity.m %
%Purpose:
%To calculate and plot the height and velocity as a function of time. %
%Record of revisions:
% Date Programmer Description of change % ==== ========== ===================== % 17/05/18 liuwenya Original code %
%Define variables:
%h0 -- A height above the surface of the Earth %v0 -- A vertical velocity in the begining %t1 -- Time
%g-- The acceleration due to gravity(-9.81m/s^2) h0=input('enter date:') v0=input('enter date:') t1=input('enter date:')
%g -- The acceleration due to gravity(-9.81m/s^2) g=-9.81
%t -- Increments at 0.1 and ends at t1 t=0:0.1:t1
%Figure out a height above the surface in the final h=(g.*t.^2)./2+v0.*t+h0
%Figure out a vertical velocity in the final v=-g.*t+v0
%Plot the height and velocity as a function of time plot(t,h,'r-',t,v,'b--'); title('plot of t'); xlabel('t'); ylabel('h'); ylabel('v'); legend('h','v');
3
grid on;
(2)输入数据
Untitled
enter date:120 h0 =
120
enter date:0 v0 =
0
enter date:5 t1 =
5
5.程序运行结果
g =
-9.8100 t =
Columns 1 through 11
0 0.1000 0.2000 0.8000 0.9000 1.0000
Columns 12 through 22
1.1000 1.2000 1.3000 1.9000 2.0000 2.1000
Columns 23 through 33
2.2000 2.3000 2.4000 3.0000 3.1000 3.2000
0.3000 0.4000 1.4000 1.5000 2.5000 2.6000 0.5000 0.6000 1.6000 1.7000 2.7000 2.8000 0.7000 1.8000 2.9000 4
Columns 34 through 44
3.3000 3.4000 3.5000 3.6000 3.7000 3.8000 3.9000 4.0000 4.1000 4.2000 4.3000
Columns 45 through 51
4.4000 4.5000 4.6000 4.7000 4.8000 4.9000 5.0000 h =
Columns 1 through 10
120.0000 119.9510 119.8038 116.8608 116.0270
Columns 11 through 20
115.0950 114.0650 112.9368 104.1078 102.2929
Columns 21 through 30
100.3800 98.3689 96.2598 81.5448 78.7490
Columns 31 through 40
75.8550 72.8630 69.7728 49.1718 45.3949
Columns 41 through 50
41.5200 37.5469 33.4758 6.9888 2.2309
Column 51
-2.6250 v =
Columns 1 through 10
119.5586 94.0525 66.5846 29.3066 119.2152 110.3862 91.7472 63.2982 25.0392 118.7738 89.3438 59.9138 20.6737 118.2342 107.4432 86.8422 56.4312 16.2102 117.5965 84.2426 52.8505 11.6485 5
111.7106 108.9638 105.8246
0 0.9810 1.9620 2.9430 3.9240 4.9050 5.8860 6.8670 7.8480 8.8290
Columns 11 through 20
9.8100 10.7910 11.7720 12.7530 13.7340 14.7150 15.6960 16.6770 17.6580 18.6390
Columns 21 through 30
19.6200 20.6010 21.5820 22.5630 23.5440 24.5250 25.5060 26.4870 27.4680 28.4490
Columns 31 through 40
29.4300 30.4110 31.3920 32.3730 33.3540 34.3350 35.3160 36.2970 37.2780 38.2590
Columns 41 through 50
39.2400 40.2210 41.2020 42.1830 43.1640 44.1450 45.1260 46.1070 47.0880 48.0690
Column 51
49.0500
所得图表:
6
6.出现的问题及解决方法
(1)没有分清数组相乘和矩阵相乘。
解决办法:运行之后,电脑提示错误,然后改正。
(2)对于添加网格的函数使用方法不够了解,将xlabel('t')错写成tlabel('t')
解决办法:运行之后没有出现表格,向老师寻求帮助。
7
因篇幅问题不能全部显示,请点此查看更多更全内容