clc
clear all
x0 = 0; x1 = 4; i = 1;
f = @(x)( x^3 - x -10);
t=0.00009;
while( 1 )
temp=x1;
c = (((x0*f(x1))-(x1*f(x0)))/(f(x1)-f(x0)));
if(abs(f(c)) <=t || x1==c || x0==c)
f(c)
fprintf('Root is: '), c
i
break;
else
x1=c;
x0=temp;
end
i = i+1;
end
clear all
x0 = 0; x1 = 4; i = 1;
f = @(x)( x^3 - x -10);
t=0.00009;
while( 1 )
temp=x1;
c = (((x0*f(x1))-(x1*f(x0)))/(f(x1)-f(x0)));
if(abs(f(c)) <=t || x1==c || x0==c)
f(c)
fprintf('Root is: '), c
i
break;
else
x1=c;
x0=temp;
end
i = i+1;
end
No comments:
Post a Comment