
bisection method problem
1.write a matlab function Bisection.m which takes as input a function f(x) and a bracketing interval[a b] and outputs the root of the function f(x). Hint: you will find the matlab function feval.m useful here.
2. Use Bisection.m created in question 1 to find the smallest positive root of the equation:
x^33.23*x^25.54*x+9.84=0.
verify your result by
1. Plotting the function in Matlab.
2.by using the inbuilt matlab fzero function
Submit in addition to your code ,plot of the error. How many iterations are required for the error to be in order of 10^3.
here is my script:
function zero = bisection(f,a,b,tol)
n=0
fa = feval(f,a);
fb = feval(f,b);
while 1
if ( abs(ba) <= tol )
zero = (a+b)/2;
n=n+1
return
end
c = (a + b)/2;
fc = feval(f,c);
if ( fa*fc > 0)
a = c;
fa = fc;
else
b = c;
fb = fc;
end
end
disp(n)
root
err=abs(ba)
here is what i get when i run my command:
function f =rt(x)
f=x^33.23*x^25.54*x+9.84
>> bisection('rt',0,2,(10^3))
n =
1
ans =1.2300
i am not sure,if my value for n is right or wrong also i donot know how to plot the error. any suggestions for the code of the graph.sorry no one was replying the urgent section,so i posted this in some other section.