Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

part A solution code: function height = L2PartA(theta,xtarget) vx=1000*cos(theta); vy=1000*sin(theta); t=xtarget/vx; height=vy*t-(9.81/2)*t^2 end Code to call function: L2PartA(pi/8,5000) Need to solve Part B in Matlab

image text in transcribed

part A solution code:

function height = L2PartA(theta,xtarget)

vx=1000*cos(theta);

vy=1000*sin(theta);

t=xtarget/vx;

height=vy*t-(9.81/2)*t^2

end

Code to call function:

L2PartA(pi/8,5000)

Need to solve Part B in Matlab

Simple Projectile Motion We need very little math for this problem. First, the vertical height of the projectile at a given moment in time, y(t), will be given (approximately) by (t) = tt - Phi, where v = 1000 sin() and the horizontal position is given by *(t) = vzt, where ve = 1000 cos(@). We will need to determine the correct angle, 0, to hit our target. We have hit the target if for some time t, r(t) = 5000 and y(t) = 500. Part A In order to solve this problem, our first step will be to code a function that takes as an input an angle, e, as well as the value of Itarget and returns the value of y(t) at the time t where r(t) = Itarget. With a little mathematics, this is not to hard to determine. First figure out the time at which (t) = Itarget, then use that time to evaluate y(t) and return that value. Use the above equations to first find t and then y. That is you will have a function L2PartA which inputs and target and output a value for the height of the cannon ball after it has traveled the horizontal distance to the target. In order for you to be able to test your code, if target = 5000 and @= 7/8 radians, then the function should return a value of 1.927403688037477e+03. Please note, your code must use radians and not degrees! MATLAB's Grader Submit your code in Part A. Part B When doing part B, in your code entered into MATLAB's Grader, you may freely use a function called L2PartA that is as described in Part A and works correctly. You can do this, even if you have not finished Part A though it will only work in ZyBooks). You do not need to reenter a function called L2PartA. For Part B, you will be given a target (Itarget, Ytarget) and you need to determine the correct angle 6 you need in order to hit the target with the cannon. First we will use a Monte Carlo method. Write a function that has two inputs for Itarget and ytarget. Inside the function, set a value for N. The randomly select a fixed number (N) of angles from 1/100 to 2/3. Then calculate the angle from your random list that produces the minimum difference between the y value returned by L2PartA and ytarget. Have the function return this angle and the difference between Ytarget and the actual value calculated for that angle. Run this code several time with Itarget = 5000 and ytarget = 1000 and be sure that it produces a result accurate to the nearest meter each time. If it does not even once), increase N and try again

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions

Question

Discuss how to use job evaluation to build job structures.

Answered: 1 week ago

Question

Discuss why unions exist.

Answered: 1 week ago

Question

Discuss the alternative types of health care plans.

Answered: 1 week ago