⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ball_position_velocity.asv

📁 matlab programming for engineers(2nd)书籍源码,这是一本很好的学习MATLAB编程书
💻 ASV
字号:
%  Script file: ball_position_velocity.m
%
%  Purpose: 
%  To  plot the height and velocity of a ball
%  the position and velocity of the ball as a function of time 
%  will be given by the equations h(t)=1/2*g*t^2+vo*t+ho,v(t)=g*t+vo
 
%
%  Record of revisions:
%      Date       Programmer          Description of change
%      ====       ==========          =====================
%    09/03/07    Jane                 Original code 
%
% Define variables:
%   ho        -- a initial height above the surface of the Earth at which a
%   stationary ball is released(m)
%   vo        -- a initial velocity (m/s)
%   t         -- time variable
%   h_t       -- height above the surface of the Earth (assuming no air
%              friction)(m)
%   v_t       -- the vertical component of velocity(m/s)
%   g         -- the acceleration due to gravity(-9.81m/s^2)

% set the acceleration due to gravity 
g=-9.81;
% prompts a user for the initial height of the ball in meters and velocity
% of the ball in meters per second
ho = input('Enter the initial height of the ball in meters:\n' );
vo = input('Enter the initial velocity of the ball in meters per second:\n' );

% Create an array of time variable
t = 0:.01:10;

% Calculate the height above the surface of the Earth
h_t=1/2*g*t.^2+vo*t+ho;

% Calculate the vertical component of velocity 
v_t=g*t+vo;

% plot the height and velocity as a function of time
subplot(121)
plot(t,h_t);
title('Plot of height versus time');
xlabel('t(m)');
ylabel('h(t)=');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -