HW2-Q2) MATLAB, PLEASE MAKE CODE COPYABLE
Bisect vs. False position
Copy the bisect function and modify it to create a false position function. Compute the roots of the
function
f(x)=-0.402e^(0.3x)cos(-0.5x)+5
and the number of iterations required as described below. Use an error tolerance of 0.0001%. You
will need to modify both functions to include the number of iterations as an output to the functions.
Modify the false position function to add a max iteration parameter. If the number of iterations
exceeds the maximum number of allowed iterations, the algorithm should stop and return the
current value for the root.
a) Plot the function between 17 and 38 .
b) Compute the root between 17 and 38 for both methods. Limit the false position method to
130 iterations. Display a table in the command window with the following columns:
Method, Root, and Iterations. Display the root with 10 decimal places. Just above the
table, use an fprintf statement to display a statement such as:
"Using x and x as the bounds". After the table, explain the difference in the number of
iterations between the two methods as text.
c) Create the table again but use 27 and 31 as the bounds. Explain the difference in the
number of iterations between part b and c for the False Position method as text.
d) Plot all solutions (in the figure from part a) using:
Bisection part b: a red asterisk
Bisection part c: green asterisk
False Position part b: a red square
False Position part c: a green square
2) Bisect vs.False position
Copy the bisect function and modify it to create a false position function.Compute the roots of the function f(x) = -0.402e0.3x cos(-0.5x) + 5 and the number of iterations required as described below. Use an error tolerance of 0.0001%. You will need to modify both functions to include the number of iterations as an output to the functions
Modify the false position function to add a max iteration parameter. If the number of iterations
exceeds the maximum number of allowed iterations,the algorithm should stop and return the
current value for the root. a) Plot the function between 17 and 38.
b) Compute the root between 17 and 38 for both methods. Limit the false position method to 13o iterations. Display a table in the command window with the following columns: Method,Root,and Iterations. Display the root with 1o decimal places. Just above the table,use an fprintf statement to display a statement such as:
"Using X and X as the bounds". After the table, explain the difference in the number of iterations between the two methods as text
c) Create the table again but use 27 and 31 as the bounds. Explain the difference in the
number of iterations between part b and c for the False Position method as text
d) Plot all solutions (in the figure from part a) using: Bisection part b: a red asterisk False Position part b: a red square Bisection part c: green asterisk False Position part c: a green square