Question
In MATLAB: Suppose a user wants to make a root finder in Matlab. Create a script that does the following: Allows the user to enter
In MATLAB: Suppose a user wants to make a root finder in Matlab. Create a script that does the following:
- Allows the user to enter a function, f(x), the end-points of the plot window and the method to find the root.
- Plot the function for the user to view the location of roots.
- Using a case-switch, call 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!
- Plot the points generated through each pass in the algorithmic loop.
- Return the root, the time elapsed and the number of iterations.
*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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started