Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PART 1 : Trajectories Part 1 focuses on how to use Matlab to calculate the traje

ID: 641299 • Letter: P

Question

PART 1: Trajectories
Part 1 focuses on how to use Matlab to calculate the trajectory of an angry bird.

A trajectory is the path an object follows over time. For example, the dotted lines in the figure below represent possible trajectories of an angry bird.

Let?s define a few variables we are going to need to describe our trajectory.
? v0 is the initial velocity (speed) of the object,
? ? is the angle at which the object is fired,
? (xt, yt) is the 2D position of the object at time t
? g is the strength of gravity (on Earth, g = 9.8 m/s2)

Also, assume that
? the beginning of the trajectory occurs at time t = 0,
? the ground is at y=0;
? When t = 0, (x0, y0) = (0,0)

With these variables defined, we can now define the following mathematical equations that describe the position of an object as a function of time.
xt = v0 * cos (?) * t
yt = v0 * sin(?) * t ? 0.5 * g * t2

Build It

1. Write a function called trajectory() that returns the 2D position (xt, yt) of an object at a given time t. Pass the object?s initial velocity v0, angle ?, current time t, and gravity (g) as input arguments. If the user does not specify gravity as an input, your function should assume g = 9.8 m/s2.

2. Write a function called peakheight() that returns the height of the object when it reaches the peak of the trajectory (the highest height the object reaches).

3. Write a function called timeflight() that returns the total duration of the object?s flight (the time at which the object hits the ground).

4. Write a function called range() that returns the total horizontal distance the object travels.

Hint: Equations for peakheight(), timeflight() and range() can be found by rearranging the trajectory equations above.

Explanation / Answer

%save this as trajectory.m

function [xt,yt]=trajectory(v0,theta,t,g)
if (nargin < 4) || isempty(g)%if user does not give g assume g=9.8
g = 9.8;
end
xt = v0 * cos (theta) * t;
yt = v0 * sin(theta) * t - 0.5 * g * t^2;
end

%end of file

%save this as peakheight.m

function H=peakheight(v0,theta,g)
if (nargin < 3) || isempty(g)%if user does not give g assume g=9.8
g = 9.8;
end
H = (v0^2*sin(theta)^2)/2*g;
end

%end of file

%save this as timeflight.m

function T=timeflight(v0,theta,g)
if (nargin < 3) || isempty(g)%if user does not give g assume g=9.8
g = 9.8;
end
T = (2*v0*sin(theta))/g;
end

%end of file

%save this as range.m

function R=range(v0,theta,g)
if (nargin < 3) || isempty(g)%if user does not give g assume g=9.8
g = 9.8;
end
R = (v0^2*sin(2*theta))/g;
end

%end of file