2 views (last 30 days)

as an example if we take x^3-8*x^2+17*x-10,i want to calculate this zero polynomial using dichotomy method but it does'nt give me the good result , can anyone help to solve this problem ?

clc

clear all

close all

syms x

f=input( 'donnez la fonction :' );

a=input( 'donnez la borne minimal de l intervalle :' );

c=input( 'donnez la borne maximal de l intervalle : ' );

b=(a+c)/2;

v=[];

n=[];

p=0;

for i=1:100

x(i)=(a(i)+b(i))/2;

if abs(f(x(i)))==0

v=[v,x(i)];

break

end

if (f(a(i))*f(x(i))<0)

a(i+1)=a(i);

b(i+1)=x(i);

else

b(i+1)=b(i);

a(i+1)=x(i);

end

end

for j=1:100

x(j)=(b(j)+c(j))/2;

if abs(f(x(j)))==0

n=[n,x(j)];

break

end

if (f(b(j))*f(x(j))<0)

b(j+1)=b(j);

c(j+1)=x(j);

else

c(j+1)=c(j);

b(j+1)=x(j);

end

end

p=[v,n]

Torsten
on 26 Jan 2018

https://de.mathworks.com/matlabcentral/fileexchange/33748-bisection-method?focused=5203297&tab=function

Best wishes

Torsten.

Walter Roberson
on 26 Jan 2018

Your line

if abs(f(x(j)))==0

is questionable. abs() of an expression can only equal 0 if the value itself is 0, in which case there would be no point in taking abs():

if f(x(j)) == 0

However, with polynomials, numeric round-off error is a common problem (which gets worse with higher degree), so it might not be possible to find an f(x(j)) that is exactly 0. Instead you might get to the point of finding two numbers that are adjacent in floating point representation such that f() of one of them is on one side of 0 and f() of the other of them is on the other side of 0 -- for example 1.834e-34 and -9.5192e-35 . Therefore instead of testing for exactly 0, you should test that the absolute value is less than a tolerance.

Opportunities for recent engineering grads.

Apply TodayFind the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 3 Comments

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/379128-i-want-to-calculate-a-zero-of-a-function-can-anyone-help-me#comment_528712

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/379128-i-want-to-calculate-a-zero-of-a-function-can-anyone-help-me#comment_528712

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/379128-i-want-to-calculate-a-zero-of-a-function-can-anyone-help-me#comment_528713

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/379128-i-want-to-calculate-a-zero-of-a-function-can-anyone-help-me#comment_528713

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/379128-i-want-to-calculate-a-zero-of-a-function-can-anyone-help-me#comment_528722

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/379128-i-want-to-calculate-a-zero-of-a-function-can-anyone-help-me#comment_528722

Sign in to comment.