- #1

- 2

- 0

Im new to Matlab, and my lecturer asked me to do his question which is:

Find one root of equation 8x^3-36x^2+54x-12=0 using the bisection method.

Your answer must includethe number of iterations.

Ive already read the Introduction to MATLAB 7, and Numerical Methods for Engineers. And the only clue that i get is:

Step 1: choose lower x1 and upper x2 guesses for the root such that the function changes sign over interval. This can be checked by ensuring that f(x1).f(x2)<0

Step 2: an estimate of the root xr is determined by xr=(x1+x2)/2

Step 3: Make the following evaluations to determine in which subinterval the root lies

a) if f(x1).f(x2)<0, the root lies in the lower subinterval. Therefore, set x2=xr and return to step 2

b) if f(x1).f(x2)>0, the root lies in upper subinterval. Therefore, set x1=xr and return to step 2

c) if f(x1).f(x2)=0, the root equals xr, terminate the computation.

This is what i did, and i know it is completely wrong.

can any body please help/guide me solving this question, PLEASE!!

%program question 1 Numerical analysis

%Find one root of equation 8x^3-36x^2+54x-4(P+Q)=0

%where P=1,Q=2

disp('8x^3-36x^2+54x-12=0')

disp('choose lower x1 and upper x2 guesses for the roots')

x1=input('x1=')

x2=input('x2=')

a=x1

b=x2

f(x1)=(8*x1^3)-(36*x1^2)+(54*x1)-12

f(x2)=(8*x2^3)-(36*x2^2)+(54*x2)-12

xr=(a+b)/2

iter=0

e=f(x1)*f(x2)

for e=0

while e<0

xr=(a+xr)/2

iter=iter+1

end

while e>0

xr=(xr+b)/2

iter=iter+1

end

end

disp('root')

disp(xr)

disp('number of iterations')

disp(iter)