Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MATLAB Content: for loops, rand random number function, if conditional statement, abs function, binary operators, function handles, min function, linspace Mathematical/Numerical Content: bisection algorithm, secant

MATLAB Content: for loops, rand random number function, if conditional statement, abs function, binary operators, function handles, min function, linspace

Mathematical/Numerical Content: bisection algorithm, secant method, Newtons method

Avalanche Control In order to prevent Avalanche disasters, cannons have been fired into the mountains to create controlled avalanches. The scenario for this lab is simple. You have a cannon that fires a projectile at a speed of 1000 m/s per second. We are going to ignore wind resistance just to simplify the mathematics (but we could add it in later if we wished) and predict the firing angle to hit a target some horizontal distance xtarget away and at a vertical height ytarget above where the cannon is.

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

y(t) = vyt 9.81/2 (1)

where vy = 1000 sin() and the horizontal position is given by x(t) = vxt, (2)

where vx = 1000 cos(). We will need to determine the correct angle, , to hit our target. We have hit the

target if for some time t, x(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, , as well as the value of xtarget and returns the value of y(t) at the time t where x(t) = xtarget. With a little mathematics, this is not to hard to determine. First figure out the time at which x(t) = xtarget, 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 xtarget 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 xtarget = 5000 and = /8 radians, then the function should return a value of 1.927403688037477e+03. Please note, your code must use radians and not degrees!

MATLABs Grader Submit your code in Part A.

Part B When doing part B, in your code entered into MATLABs 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 (xtarget,ytarget) and you need to determine the correct angle 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 xtarget and ytarget. Inside the function, set a value for N. The randomly select a fixed number (N) of angles from /100 to /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 xtarget = 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.

MATLABs Grader Submit your code in Part B.

Avalanche Lab (All Parts)

Mark Lyon

February 10, 2019

Part C When doing part C, you may again freely use a function called L2PartA. For Part C, you will be again be given a target (xtarget,ytarget) and you need to determine the correct angle you need in order to hit the target with the cannon. Write a function that has two inputs for xtarget and ytarget. Inside the function, set a value for N. The generate N equidistant angles from /100 to /3. Then calculate the angle from your 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 different values for xtarget (2500 xtarget 7500) and ytarget (500 ytarget 1500) 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.

MATLABs Grader Submit your code in Part C.

Part D A much better way to solve these type of problems is using Newtons method, the secant method, or bisection. We will focus on the Secant Method now.

The Secant Method proceeds as follows: Given a couple of guesses (hopefully good ones) xj and xj1 for the root of a function f, it finds a hopefully more accurate next guess xj+1 given by

xj+1 =xj f(xj) . (3) f(xj)f(xj1)

xj xj1

Write a function called MySecant which takes as inputs, a function f, two initial guesses, and a tolerance. The function should loop until the two most recent guesses differ by an amount less than the tolerance. It should then return the last guess obtained (which should be the most accurate).

MATLABs Grader Submit your code in Part D.

Part E For the next part of the lab, you will need code the bisection algorithm. Use the following Pseudo- Code to produce a bisection function. Note the bisection algorithm is designed to solve the problem f(x) = 0 for a given f and two values, a and b, which surround the root.

Take as an input a function you want to find the root of and two values a and b as well as a tolerance Check to ensure the function evaluated at a and evaluated at b have different sign (or one is zero) Perform a loop that ends when the difference |a b| is less than the tolerance {

Define c to be the average of a and b If the value of the f(c) times the value of the function at f(a) is negative or zero {

Let b=c

}

Otherwise

{

} }

Output the value of c

Write a function called MyBisection which takes as inputs, a function f which is a given function of one variable, two initial guesses, and a tolerance. The function should loop until the two most recent guesses differ by an amount less than the tolerance. It should then return the last guess obtained (which should be the most accurate).

Avalanche Lab (All Parts)

Let a=c

MATLABs Grader Submit your code in Part E. Mark Lyon

February 10, 2019

Part F Write a function which takes in two values, (xtarget,ytarget). You have access to a working version of L2PartA and a MySecant function that work. Call those functions in your solution but do not include them as part of it. Use the MySecant to calculate and return the correct angle to fire the cannon at in order to hit the target. Pick appropriate starting angles.

MATLABs Grader Submit your code in Part F.

Part G Write a function which takes in two values, (xtarget, ytarget). You have access to a working version of L2PartA and a MyBisection function. Call those functions in your solution but do not include them as part of it. Use the MyBisection to calculate and return the correct angle to fire the cannon at in order to hit the target. Pick appropriate starting angles. This code should be very similar to the code you wrote for Part F.

MATLABs Grader Submit your code in Part G.

yes we are using the Matlab software to solve this problem

ok then how long will researching Matlab take

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

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

Students also viewed these Databases questions

Question

5. We have often heard caregivers tell their children?

Answered: 1 week ago