Please use MATLAB and explain the steps Objectives Write a f

Please use MATLAB and explain the steps.

Objectives

Write a function that accepts variable number of arguments

Write a function that returns multiple arguments

Use fprintf (or sprintf) for formated output to the screen

Review physics of a projectile trajectory with no air resistance

Instructions

Write a Matlab function called work09.m that computes the maximum horizontal and vertical distance of a projectile and the total travel time, given the firing angle and initial velocity. Also, accept a third optional parameter that adjusts the gravitational constant (g = 9.8065 m2/s default). The angle input is degrees from horizontal, and velocity is m/s. You may need to consult a physics textbook or a reputable web resource such as https://en.wikipedia.org/wiki/Projectile_motion.

Your function must do the following:

Use nargin to determine whether there is an optional g parameter given

Calculate the correct vertical and horizontal distances, and total travel time

Have sufficiently detailed comments in the appropriate location in the function such that typing help work09 would completely describe how to use your function

Use appropriate formatting for output information to the screen

Sample Output (four possibilities shown)

xm = 22.2621

ym = 4.3483

tm = 1.883

ans = 22.2621

Solution

function [x_max, y_max, t_max]= work09(angle,v0)
t = 0;
y = 0;
x = 0;
g = 9.802;
y_a = [];
t_a = [];
x_a = [];
y = v0*t*sin(angle)-0.5*g*t.^2;
x = v0*t*cos(angle);
y_a(end+1) = y;
while ge(y,0)
y = v0*t*sin(angle)-0.5*g*t.^2;   
x = v0*t*cos(angle);
t = t + 0.1;   
y_a(end+1) = y;
x_a(end+1) = x;
t_a(end+1) = t;
end
x_max = max(x_a);
y_max = max(y_a);
t_max = max(t_a);
end

Please use MATLAB and explain the steps. Objectives Write a function that accepts variable number of arguments Write a function that returns multiple arguments
Please use MATLAB and explain the steps. Objectives Write a function that accepts variable number of arguments Write a function that returns multiple arguments

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site