Thursday 14 April 2011

Bisection Method For Finding Roots Of equation Matlab Code

fed up of doing calculations by hand to find the roots of an equation by "BISECTION METHOD" (one of  the bracketing techniques to solve an equation) the solution is simple and reliable write a piece of MATLAB code.Cant do this???? thats what i am here for !! here is the required code !! this code will
1.find the mean value at each iteration
2.plot the graph of true error
3.plot graph of approximate error
change the function and initial bracket according to your requirements!!
here is the code




clc
clear all
close all
xl=0;
xu=1;
xr=0;
ethresh=2;
xt=0.5671;
et=[];
ea=[];
for i=1:10
f_xl = exp(-xl)-xl;
f_xu = exp(-xu)-xu;
bracket = [xl xu];
xrold=xr;
xr=(xl+xu)/2
ea(i)=abs((xr-xrold)*100/xr);
et(i)=(xr-xt)/xr;
f_xr=exp(-xr)-xr;


if(f_xl*f_xr<0)
    xu=xr;
else if(f_xu*f_xr<0)
       xl=xr;
    else
        ea=0;
    end
    
    next_bracket=[xl xu]
end
end
plot(1:length(et),et,'r')
grid on
hold on
plot(1:length(ea),ea,'b')


4 comments:

  1. Hello there! Do you use Twitter? I'd like to follow you if that would be ok. I'm undoubtedly enjoying your blog and look forward to new updates.


    Feel free to surf to my web site - bmi calculator

    ReplyDelete
  2. Appreciate this post. Let me try it out.

    Also visit my weblog: free minecraft account

    ReplyDelete
  3. Casino site, bonus, promotions and much more!
    This bonus is one of the best casinos to get started with. You can sign up and start playing, earn luckyclub.live money or play at a casino site!

    ReplyDelete