a=input('Enter the function = ', 's');
f= inline(a);
a=0; b=1;x=0;
for i=1:inf
if f(a)*f(b)<0
break
else
a=a-i; % replace - by + to get positive root
b=b+i;
end
end
for i=2:inf
x(i)= (a+b)/2;
if f(x(i))*f(a)<0
b=x(i);
else
a=x(i);
end
if abs(x(i)-x(i-1))<=0.0001
break;
end
end
Iteration=i
Root=x(i)
f= inline(a);
a=0; b=1;x=0;
for i=1:inf
if f(a)*f(b)<0
break
else
a=a-i; % replace - by + to get positive root
b=b+i;
end
end
for i=2:inf
x(i)= (a+b)/2;
if f(x(i))*f(a)<0
b=x(i);
else
a=x(i);
end
if abs(x(i)-x(i-1))<=0.0001
break;
end
end
Iteration=i
Root=x(i)
No comments:
Post a Comment