Question: Suppose an individual wants to create a root finder function. Using MATLAB, create a script for the user that does the following: 1. Allows an

Suppose an individual wants to create a root finder function. Using MATLAB, create a script for the user that does the following:
1. Allows an individual to enter a function, f(x), the end-points of the plot window, and the method to find the root. *(The methods needed are below)
2. Plots the function for the user to view the location of roots.
3. Uses a case-switch, call each function bisection.m, fixed.m, newton.m or secant.m (each of these should prompt the user for the necessary input information). *Note: these are functions you will write!
4. Plot the points generated through each pass in the algorithmic loop.
5. Return the root, the time elapsed, and the number of iterations.
Run your script with the following function using each method: f(x) = x^2 sin(x)
*Note: find the root to within 1.e 16 accuracy.
*For part 3
Bisection Method
% Bisection Method
% a is a point left of the root
% b is a point right of the root
% m is the point halfway between a and b
m = a + (b-a)/2;
if sign(f(a)) == sign(f(m))
a = m;
else
b = m;
end
Fixed-point Method
% Fixed-point f(x) = g(x) - x = 0
% which implies: x(n+1) = g(x(n))
p = g(p0);
Newton Method
% Newtons Method
% x is the guess
% xn is the new guess
% f1 is the first derivative
xn=x-f(x)/f1(x);
Secant Method
% Secant Method
% x0 and x1 are guesses that are distinct
% xn is the new guess that will connect to x1
xn = x1 - f(x1)*(x1-x0)/(f(x1)-f(x0));
Please show all work. Thanks!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!