Question
If you wrote the ball throwing script for question 2 in Credit Task 1, turn it into a function. Write a function file named DTask1_f.m
If you wrote the ball throwing script for question 2 in Credit Task 1, turn it into a function. Write a function file named DTask1_f.m and make the function declaration that takes v and theta as inputs and returns the distance at which the ball hits the ground: distance = DTask1_f(v, theta). The initial height of the ball is at 1.5 m. We generally dont want functions to plot things every time they run, so remove the figure command and any plotting commands from the function. To be able to simulate a wide range of v and theta, make the time go until 10 sec and add an if statement that will display the warning The ball does not hit the ground in 10 seconds. if that turns out to be the case (use isempty). Also, if the ball doesnt hit the ground in 10 seconds, you should return NaN as the distance. To test your function, write a script DTask1.m to throw the ball with the same velocity v=4 m/s but different angles theta = 0:60 and plot the distance as a function of angle theta. The plot should look something like the figure below. You will need to run DTask1_f within a loop in order to calculate the distances for various thetas. Change velocity v=60 m/s, test if your program display the warnings and plot the figure.
Credit Task 1 -http://www.chegg.com/homework-help/questions-and-answers/steps-need-follow-also-add-meaningful-comments-code-write--start-new-file-matlab-editor-sa-q23238079
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started