Finding Root of 8x^3-36x^2+54x-12=0 Using Bisection Method

In summary, the student is new to using MATLAB and needs help solving a numerical analysis problem using the bisection method. They have read some textbooks but are struggling to implement the algorithm correctly. After receiving guidance and clarification, they plan to work on two more questions on their own.
  • #1
azizul85
2
0
Hi,
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 anybody 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)
 
Physics news on Phys.org
  • #2
azizul85 said:
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.

I think there is a problem here with the algorithm. What you're supposed to do is start with an interval [x1,x2] on which you know f changes sign (therefore it crosses zero), then determine whether the zero is in the left half of the interval or the right half, and then cut the interval in half and keep the half which is known to contain the zero crossing. Repeat this and your interval should approach the root. To check which side the zero crossing is in, you need to check the sign of f(x1)*f(xr) or f(xr)*f(x2), NOT f(x1)*f(x2). You want to check one half of the interval. As you have it, it checks the entire interval, which is useless because you know it's in there, and eventually it will take the wrong half and you will be screwed.

Code:
%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)

You have a good start here, but there's a few things you need to change. To avoid having to use inline functions you should evaluate
fx1=(8*x1^3)-(36*x1^2)+(54*x1)-12
fxr=(8*xr^3)-(36*xr^2)+(54*xr)-12
at each iteration inside the loop. Also move the calculation of e inside the loop. And since I don't like while loops, I would change to
if e>0,
elseif e<0
end
And e probably won't ever be zero exactly, so add something like
if norm(e)<1e-12 to tell when e is very small
I don't know if it was intentional, but if you put a semicolon ; at the end of the line, it won't display the result at every line.
And to prevent getting stuck in an infiinite loop, change 'while e=0' to 'for iter = 1:100', then you can eliminate iter=iter+1.
And keeping track of a,b,x1,x2 seems repetitive, so I would eliminate a,b and only use x1,x2.

In the end you will have something like this
Code:
%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=')
xr=(a+b)/2;

for iter = 1:100
    fx1=(8*x1^3)-(36*x1^2)+(54*x1)-12; % compute f at left end
    fxr=(8*xr^3)-(36*xr^2)+(54*xr)-12; % compute f in middle
    e=fx1*fxr;  % check if zero is in left half
    if e<0  % root is in left half of interval
        x2=xr;  % this cuts the interval in half, keeping the left half
        xr=(x1+x2)/2; % compute center of new interval
    elseif e>0 % root is in right half of interval
        x1=xr; % this cuts interval in half, keeping right half
        xr=(x1+x2)/2;  % compute center of new interval
    end
    if norm(e)<1e-12, break, end
end
disp(['root = ',num2str(xr)])
disp(['number of iterations = ', num2str(iter)])
Let me know if something I said doesn't make sense or seems wrong.
 
  • #3
Hi Lebrad,
After going through the books and your method.
I realize my mistake.
Your method is definitely correct.
Thank you very much. I definitely need your help on that one as that is the 1st question that i need to do using Matlab.
Now, i need to do another 2 questions,
which i think, its better for me to try,
thanks again.
cheers.
 

1. What is the Bisection Method?

The Bisection Method is a numerical algorithm used to find the root of a given function by repeatedly dividing an interval into two and checking which subinterval contains the root. It is a simple and robust method that guarantees convergence to the root within a given tolerance.

2. How is the Bisection Method used to find the root of a polynomial function?

The Bisection Method is used by first ensuring that the given function is continuous and changes sign over a given interval. Then, an initial guess is made for the root, and the interval is divided into two subintervals. The subinterval that contains the root is determined by checking the sign of the function at the midpoint of the interval. This process is repeated iteratively until the root is found within the desired tolerance.

3. What is the formula for the Bisection Method?

The formula for the Bisection Method is:
xn+1 = (an + bn)/2, where xn+1 is the midpoint of the interval [an, bn].

4. How do you determine the number of iterations needed for the Bisection Method?

The number of iterations needed for the Bisection Method depends on the desired tolerance and the initial interval chosen. The number of iterations can be estimated using the formula:
n = log2((b-a)/tolerance), where b and a are the endpoints of the initial interval and tolerance is the desired tolerance.

5. What are the advantages of using the Bisection Method for finding roots?

The Bisection Method has several advantages, including its simplicity and robustness. It also guarantees convergence to the root within a given tolerance and does not require the function to be differentiable. Additionally, it can be used to find multiple roots within an interval and is less sensitive to initial guesses compared to other root-finding methods.

Similar threads

  • Precalculus Mathematics Homework Help
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Replies
1
Views
9K
  • Topology and Analysis
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Precalculus Mathematics Homework Help
Replies
2
Views
2K
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
5K
Back
Top