Question #8120

Expert... help me on this problem, i already try many times during this 2 week, but i cant the answer by using m-files.

Determine the real root of f(x)=-26+85x-91x^2+44x^3-8x^4+x^5

Using bisection to determine the root to εs=10 %. Employ initial guesses of xl=0.5 and xu=1.0.

You need to solve the above problem using Matlab

Determine the real root of f(x)=-26+85x-91x^2+44x^3-8x^4+x^5

Using bisection to determine the root to εs=10 %. Employ initial guesses of xl=0.5 and xu=1.0.

You need to solve the above problem using Matlab

Expert's answer

function

[c,err,yc]=bisection(f,a,b,err_tolerance)

ya=feval(f,a);

yb=feval(f,b);

if

ya*yb >

0,return,end

maxx=1+round((log(b-a)-log(err_tolerance))/log(2));

for

k=1:maxx

c=(a+b)/2;

yc=feval(f,c);

if yc==0

a=c;

b=c;

elseif

yb*yc>0

b=c;

yb=yc;

else

a=c;

ya=yc;

end

if b-a <

err_tolerance, break,end

end

c=(a+b)/2;

err=abs(b-a);

yc=feval(f,c);

[c,err,yc]=bisection(f,a,b,err_tolerance)

ya=feval(f,a);

yb=feval(f,b);

if

ya*yb >

0,return,end

maxx=1+round((log(b-a)-log(err_tolerance))/log(2));

for

k=1:maxx

c=(a+b)/2;

yc=feval(f,c);

if yc==0

a=c;

b=c;

elseif

yb*yc>0

b=c;

yb=yc;

else

a=c;

ya=yc;

end

if b-a <

err_tolerance, break,end

end

c=(a+b)/2;

err=abs(b-a);

yc=feval(f,c);

## Comments

kenry06.04.12, 07:11but y it appear those error comment?

??? Error: File: Untitled.m Line: 6 Column: 1

Function definitions are not permitted in this context.... tis error come out by the "function" word...

## Leave a comment