how do I write a script in MATLAB that should perform the fo

how do I write a script in MATLAB that should perform the following steps: 1. Ask the user to input two arguments: (i) angle at which projectile was launched; note that the user prefers to input the angle in degrees (ii) speed v at which projectile was launched 2. Check whether launch angle and launch speed are positive real numbers. Display error message and abort if not. 3. Starting with time t = 0, and incrementing it by 1 s each time, repeatedly compute the coordinates (x,y) of the projectile (note that the launch location has the coordinates (0, 0)). Collect values in one-dimensional arrays X and Y. 4. Stop when the altitude becomes negative. 5. Plot the curve of the values in Y vs X. Use MATLAB’s function plot: plot(X,Y);

Solution

theta = input(\"Enter angle in degree: \");

v = input(\"Enter velocity(meter per second): \");

if theta <= 0 || v <= 0

    fprintf(\"angle or velocity cannot be -ve or 0\");

    return

end

vx = v*cosd(theta);

vy = v*sind(theta);

x = [0];

y = [0];

g = 9.8;

t = 0;

while (true)

    t++;

    xnew = vx * t;    

    ynew = vy * t - 0.5*g*t*t;

    if ynew < 0

       break;

    end

    x = [x xnew];

    y = [y ynew];

end

plot (x, y)


Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site