Monday 2 September 2013

Bisection Method Code

clc
clear all
a=1,b=2,n=20,t=0.005,i=1,x=a;
fa=x^3+4*x^2-10;
while i<=n
    p=(a+b)/2;
    x=p;
    fp=x^3+4*x^2-10;
    fpt=fp;
    fpt=(fpt^2)^0.5;
    fpt
        if fpt<=0.005
        fpt
        x
        i
        break;
    end
    i=i+1;
    if fa*fp>0
   
        fa=fp;
        a=p;
   
    else
        b=p;
    end
end 

No comments:

Post a Comment