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

Using matlab, write the code for the following problem: The height and speed of

ID: 3676739 • Letter: U

Question

Using matlab, write the code for the following problem:

The height and speed of a projectile (such as a thrown ball) launched with a speed of v_0 at an angle alpha to the horizontal are given by h(t) = v__0 t sin alpha - 1/2 gt^2 and v(t) = square v^2_0 - 2v0 gt sin alpha + g^2 t^2 where g is the gravitational acceleration. The projectile will strike the ground when h (t) = 0, which gives the time to hit t__hit = 2 (v_0/g) sin alpha. Use the switch structure to write a MATLAB program to compute (i) the maximum height reached by the projectile, (ii) the total horizontal distance traveled, and (iii) the time to hit. The program should accept as input the user's choice of which quantity to compute and the values of v0, alpha g. Test the case where v_0 = 40 (m/s), alpha = 30 degree, and g = 9.81 (m/s^2) and show the corresponding analysis results.

Explanation / Answer

v0= input('Initial velocity(m/s): ');

a= input('Angle of projection(in degrees): ');

h= input('Time step (in seconds): ');

a=a*pi/180;

g=9.8; %acceleration due to gravity in m/s^2

xmax=v0^2*sin(2*a)/g;

ymax=v0^2*sin(a)^2/(2*g);

td=2*v0*sin(a)/g;           %total time

x1=0;

y1=0;

figure('color','white');

for t=0:h:td+h

    x=v0*t*cos(a);          %analytic solution for x

    y=v0*t*sin(a)-g*t^2/2; %analytic solution for y

    plot(x,y,'r*',x1,y1,'bo')

    hold all

    xlim([0 1.1*xmax]);

    ylim([0 1.1*ymax]);

    title('Projectile Motion');

    xlabel('Distance in meter');

    ylabel('Height in meter');

    getframe;

    x1=x1+h*v0*cos(a);      %Euler's method for x

    y1=y1+h*(v0*sin(a)-g*t);%Euler's method for y

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote