Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Industries Academia Support User Community Company

 

Student Center

The physics of baseball


A pitcher throws a baseball at 50m/s at an angle of 36.7 degrees in the air. How far will the ball go before it hits the ground? How high will the ball go? How long does it take to hit the ground ?

There is more than one way to solve this problem:

  1. Use Calculus
  2. Use MATLAB ODE solvers
  3. Solve it symbolically

Using MATLAB ODE solvers:

function dxdt = trajectoryode(t , x)

dxdt(1)= x(2);
dxdt(2,1)= 0;
dxdt(3,1) = x(4);
dxdt(4,1) = -9.8;

MATLAB script:

v0= 20;
theta = deg2rad(36.7);
v0x = v0*cos(theta);
v0y = v0*sin(theta);
x0=0;
y0=0;

[t,xsol]=ode45(@trajectoryode,[0 2.5], ...
[x0 v0x y0 v0y],[]);

x=xsol(:,1);
vx=xsol(:,2);
y=xsol(:,3);
vy=xsol(:,4);

plot(x,y)

axis([0 300 -40 50])
hold on
for i= 1:size(x)
   plot(x,y,'+')
   pause(0.2)
end

axis([0 300 -40 50])
plot(t,y)
plot(t,vy)

Solving the question symbolically:

x0=0;
y0=0;
v0= 20;
theta = deg2rad(36.7);
v0x = v0*cos(theta);
v0y = v0*sin(theta);

syms t

ay=-9.8;
vy=int(ay,t)+v0y;
y= int(vy,t)+y0;

ax=0;
vx=int(ax,t)+v0x;
x= int(vx,t)+x0;

To reduce number of digits use the function VPA:

Y=vpa(y,3);
X=vpa(x,3);

Pretty(X)
Pretty(Y)

16.0 t

2
-4.90 t + 12.0 t

As expected:

Ezplot(X,[0 2.5])
Ezplot(Y,[0 2.5])

Time to reach back to the ground:

solve(Y)

ans =

[0]
[ 2.4489795918367346938775510204082]

Range=subs(X,t, 2.44897959183673469387755102040)

For maximum height:

Solve(vy)

ans = 1.2196431570929004168164635989435

MaxHeight=subs(Y,t, 1.2196431570929004168164635989435)

Contact sales
Software evaluation for instructors
Free technical kit
E-mail this page

MATLAB & Simulink Student Version

Includes full-featured versions of both MATLAB and Simulink

From School To Industry

"The only limit to MATLAB is your imagination."
Carl Klopstein
Radar Systems Engineer