Question: check the code: function project _ 5 ( ) % PROJECT _ 5 project _ 5 ( ) models the path of a projectile launched
check the code:
function project
PROJECT project models the path of a projectile launched
from a raised platform.
Name: Adham Elmezayen
Date: October
Class: CMPSC
Print the Splash Screen
fprintf
;
fprintfWelcome to Projectile Motion Simulation Project
;
fprintf
;
Prompt the user for inputs for velocity, angle, and height above the ground
v inputEnter the initial velocity ms: ;
theta inputEnter the launch angle degrees: ;
h inputEnter the height above the ground m: ;
Convert the launch angle to radians
thetarad degradtheta;
Decompose the velocity into x and y components
vx v costhetarad; Horizontal component
vy v sinthetarad; Vertical component
Acceleration due to gravity
g ; ms
Calculate the time to impact tf using the quadratic formula
The equation is: yt h vy t g t
We set yt to solve for t when the projectile hits the ground
Coefficients for the quadratic equation: g t vy t h
a g;
b vy;
c h;
Using the quadratic formula: t b pm sqrtbaca
discriminant b a c;
if discriminant
errorNo real solution for time to impact. Check inputs.;
end
tf b sqrtdiscriminant a; Taking the positive root
Create additional time variables for different points
t; Initial time
t tf ; th of the flight time
t tf ; Half of the flight time
t tf ; th of the flight time
t tf; Final time impact
Time array
t t t t t t;
Calculate the five horizontal and vertical positions
x vx t; Horizontal position: x vx t
y h vy t g t; Vertical position: y h vy t g t
Calculate the five horizontal and vertical velocities
vx vx onessizet; Horizontal velocity remains constant
vy vy g t; Vertical velocity: vy vy g t
Print the results table
fprintf
Projectile Motion Results:
;
fprintfInitial velocity: f ms
v;
fprintfLaunch angle: f degrees
theta;
fprintfInitial height: f m
h;
fprintf
s s s s s
'Time sX mY mVx msVy ms;
Print the results for each time step
for i :lengtht
fprintff f f f f
ti xi yi vxi vyi;
end
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
