Wednesday, May 9, 2012

Regula Falsi Method Using Matlab


function[y]=f(x)
y=(x*x*x)-(2*x)-5;

Save the above function as f.m.


function regula_falsi(a,b)
if(f(b)<f(a))
    m=a;
    a=b;
    b=m;
end
if((f(a)>0 && f(b)>0)||(f(a)<0 && f(b)<0))
    fprintf('\nNo root present!!!\n');
    return;
end
c=1;
while((abs(a-b)>0.001)&&c~=50)
    c=c+1;
    m=(a*f(b)-b*f(a))/(f(b)-f(a));
    if(f(m)>0)
        b=m;
    end
    if(f(m)<0)
        a=m;
    end
end
  fprintf('\nRoot=%f\n',m);

Arguments sent to the function are:- bisection(lower approx root,upper approx root)

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. last line ........>> Arguments

    ReplyDelete