Question
Solve x^3-5x^2+3x-1=0 using the bisection method in MATLAB, specifically solving with while loop. The initial limits should be -1 and 6.The while loop should stop
Solve x^3-5x^2+3x-1=0 using the bisection method in MATLAB, specifically solving with while loop. The initial limits should be -1 and 6.The while loop should stop when the absolute value of solution, f(x), is 0.001 or smaller. The code should report the number of iteration and the value of x. Please show steps and provide explanation.
My work is as follows, and, while it works, I need the code from "for" to be solved using "while"
clear; clc;
f=@(x) x^3-5*x^2+3*x-1;
xu=6; xl=-1;
if f(xl)*f(xu)>0 disp('xl and xu have not been chosen properly') end
if f(xu)<0 xs=xu; xu=xl; xl=xs; end x while> .001 || x < -.001 x_old = x; x = x - (x^3 - 5*x^2 + 3*x -1)/(3*x^2 - 10*x +3); x = (x^3 - 5*x^2 + 3*x -1); iter = iter + 1; end for n=-1:6 xm=(xu+xl)/2; if f(xm)==0 disp('This is the answer') disp(xm) disp(n) break else if f(xm)>0 xu=xm; else xl=xm; end end end
disp('answer after 5 try') disp(xm)
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