Homework 9

$24.99 $18.99

False Position Algorithm Development Rules / Suggestions The following rules apply to ALL of our Algorithm Development Problems. These are helpful when you are testing your function and we will grade you on them. You must use the correct function name. Check number of function inputs and outputs (vector and scalar inputs) Clear variables in…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Categorys:
Tags:

Description

5/5 – (2 votes)

False Position Algorithm Development

Rules / Suggestions

The following rules apply to ALL of our Algorithm Development Problems. These are helpful when you are testing your function and we will grade you on them.

  1. You must use the correct function name.

  1. Check number of function inputs and outputs (vector and scalar inputs)

  1. Clear variables in workspace prior to running tests

  1. If variable names are not given, use appropriate and consistent names

  1. Check function for all possible number of inputs (use nargin during devel-opment to catch errors)

  2. Run algorithm for at least 2 different input values

  1. Check algorithm does not produce extraneous output

  1. Comment code for readability

False Position Algorithm

Develop a function named falsePosition.m which estimates the root of a given funtion. Your function should have the following:

Inputs:

  • func – the function being evaluated

  • xl – the lower guess

  • xu – the upper guess

  • es – the desired relative error (should default to 0.0001%)

  • maxiter – the number of iterations desired (should default to 200)

Outputs:

  • root – the estimated root location

  • fx – the function evaluated at the root location

  • ea – the approximate relative error (%)

  • iter – how many iterations were performed

Note: you will also need to develop another funciton called bisect.m. You CAN copy from Figure 5.7 in your book but don’t copy it blindly. If you make that function first, it will likely help you with Part 1 of this assignment.

FOR TESTING PURPOSES ONLY

The following is included for testing purposes. DO NOT INCLUDE THIS IN YOUR FUNCTION FILE. Remember, the function should work independently of the problem. This problem just gives you an idea of HOW to use the function you developed.

Consider a box of mass m = 25kg being pulled by a rope. The force required to move is given by:

µmg

F = cosθ + µsinθ

Let:

  • µ = 0.55

  • g = 9.81m/s2

Create a MATLAB script that solves for θ if F = 150N. Your script should create a plot of a function that is dependent on θ. Use the falsePosition function in your script file. Finally, your script should include a pair of fprintf statement(s). Each should comment on the value selected as the root, how many iterations the method took, what the approximate error is and what f is evaluated at the root. You need a fprintf statement(s) for each function. Finally, when you run each function, use the default values of the function when you can.

Note: You should change the format to long early in your script.

2

Homework 9
$24.99 $18.99