a=input('Enter the function = ', 's');
f= inline(a);
x(1)=0; x(2)=1;iteration=0;
for k=1:inf
if f(x(1))*f(x(2))<0
for i=3:inf
x(i)=(x(i-2)*(f(x(i-1)))-x(i-1)*(f(x(i-2))))/(f(x(i-1))-f(x(i-2)));
iteration=iteration+1;
if abs(x(i)-x(i-1))<=0.001 && x(i)>0
root=x(i)
iteration=iteration
break
end
end
break
else
x(1)=x(1)+1;
x(2)=x(2)+1;
end
end
f= inline(a);
x(1)=0; x(2)=1;iteration=0;
for k=1:inf
if f(x(1))*f(x(2))<0
for i=3:inf
x(i)=(x(i-2)*(f(x(i-1)))-x(i-1)*(f(x(i-2))))/(f(x(i-1))-f(x(i-2)));
iteration=iteration+1;
if abs(x(i)-x(i-1))<=0.001 && x(i)>0
root=x(i)
iteration=iteration
break
end
end
break
else
x(1)=x(1)+1;
x(2)=x(2)+1;
end
end
No comments:
Post a Comment