📄 compli_ball.m
字号:
function Compli_ball
% Script file ball.m
%
% Purpose:
% This program calculates the distance traveled by a ball
% thrown at a specified angle "theta" and a specified velocity
% "vo" form a point,ignoring air friction .It calculates the angle
% yeilding maximum range,and also plots selected trajectories.
%
% Define variables:
% conv degrees to radians conv factor
% grav The gravity accel
% ii,jj Loop index
% index The maximum range in array
% maxangle The angle that gives the maximum range
% maxrange Maximum range
% range range for a specified angle
% time Time
% theta Initial angle
% fly_time the total trajectory time
% vo The initial velocity
% vxo x-component of the initial velocity
% vyo y-component of the initial velocity
% x x-position of ball
% y y-position of ball
% Constants
conv=pi/180;
grav=-9.82;
vo=45;
range=zeros(1,91);
% Calculate maximum ranges
for ii=1:91
theta=ii-1;
vxo=vo*cos(theta*conv);
vyo=vo*sin(theta*conv);
max_time=-2*vyo/grav;
range(ii)=vxo*max_time;
end
%Write out table of ranges
fprintf('Range versus angle theta:\n');
for ii=1:5:91
theta=ii-1;
fprintf('%2d %8.4f\n',theta,range(ii));
end
% Calculate the maximum range and angle
[maxrange index]=max(range);
maxangle=index-1;
fprintf('\n Max range is %8.4f at %2d degrees.\n',maxrange,maxangle);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -