Friday, September 20, 2019

Secant Method Scilab Code

Secant Method Scilab Code


Code is Here



clc;clear
deff('y=f(x)','y=x^3-2*x-5');
x1=2,x2=3// initial values 
n=1; c=0; 
printf('successive iterations \tx1 \tx2\t x3\t f(x3)\n') 
while n==1 
    x3=(x1*f(x2)-x2*f(x1))/(f(x2)-f(x1)); 
    printf(' \t%f\t%f\t%f\t%f\n',x1,x2,x3,f(x3)); 
    if f(x3)*f(x1)>0
x2=x3;
else
x1=x3;
end
if abs(f(x3))<0.0001 then
break;
end
c=c+1;
end
printf('the root of the equation after %i iteration is: %f',c,x3 )


Secant Method Scilab Code
Secant Method Scilab Code

2 comments: