Scilab Program - regula falsi method for loop - IProgramX


Program

function[]=gf(a,b,n,f)
    for i=1:n
        c=(a*f(b)-b*f(a))/(f(b)-f(a))
        if(f(a)*f(c)<0) then b=c
        elseif(f(c)*f(b)<0)then a=c
            if((a-b)^2<0.0000001) then break
             
      end
  end
end
printf('root by regula falsi method=%f',c)
endfunction

Output:

-->deff('y=f(x)','y=x^3-2*3-5')

-->gf(2,3,45,f)
root by regula falsi method=2.223980 

Post a Comment

0 Comments