Question

Matlab Objectives Write a function that accepts variable number of arguments Write a function that returns...

Matlab

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)

>> work09(38,15);
x_max =  22.3 m
y_max =  4.35 m
t_max = 1.9 sec
>> [xm, ym, tm] = work09(38,15)
x_max =  22.3 m
y_max =  4.35 m
t_max = 1.9 sec

xm = 22.2621

ym = 4.3483

tm = 1.883

>> work09(38,15)
x_max =  22.3 m
y_max =  4.35 m
t_max = 1.9 sec

ans = 22.2621

>> work09(38,15,9.0);
x_max =  24.3 m
y_max =  4.74 m
t_max = 2.1 sec
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
Matlab Objectives Write a function that accepts variable number of arguments Write a function that returns...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT