ES 84 Project

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Mindanao State University

Fatima, General Santos City


_________________________________________________________

College of Engineering
_________________________________________________________

Numerical Methods ES 84
CEN -A
_________________________________________________________

Second Semester
School Year 2015-2016
Mondays and Thursdays 9:00-11:30 am
_________________________________________________________

Laboratory 1
Bisection
_________________________________________________________

Jovan S. Bucol
2013-0091
Engr. Rebecca Ruth R. Salas
ES 84 Lecturer

INTRODUCTION
The bisection method, which is alternatively called binary
chopping, interval halving or Bolzanos Method, is one type of incremental
search method in which the interval is always divided in half. If a function
changes sign over an interval, the function value at the midpoint is
evaluated. The location of the root is then determined as lying at the
midpoint of the subinterval within which the sign change occurs. The process
is repeated to obtain refined estimates.
ENGINEERING PROBLEM POSED
10N

Two forces 3N and (x+3)N are acting at point A, as shown in

the figure below. Determine the positive unknown value x by which the
resultant of the two forces equals 10N.

3N

A
(x + 3)N

MATHEMATICAL MODELING

10N
3N

By using force polygon for the free-body


diagram, Pythagorean Theorem can be
applied to form a quadratic equation.
Fr2 = Fx2 + Fy2 (equation 1)
102 = 32 + (x + 3)2

(x +
3)N

100 = 9 + x2 + 6x + 9
X2 + 6x 82 = 0

ANALYTICAL SOLUTION
Using quadratic formula, we can solve for x:
x=

b b24 ac
2a

x=

6 (6)24(1)(82)
2(1)

(eq. 2)

x=3+ 91
x=6.539392014
NUMERICAL SOLUTION
Using Bisection Method
Let f (x) = x2 + 6x 82
Assume an interval between x = 6 and x = 7

Iteration (1):
Xu = 7, Xl = 6, Xr =

6 +7
2

=6.5

f(Xl) f(Xr) = 7.5 > 0

Iteration (2):
Set Xl = Xr = 6.5, Xu = 7, Xr =

Iteration (3):
6.5+ 6
2

Set Xu = Xr = 6.75, Xl = 6.5, Xr =

6.75

= 6.6250

f(Xl)f(Xr) = -3.04688 < 0

f(Xl)f(Xr) = -1.23047 < 0

100=3.70
|6. 756.5
6. 75 |

100=1. 89
|6. 62506.75
6.6250 |

6.75+6.5
2

Iteration (4):
Set Xu = Xr = 6.6250, Xl = 6.5, Xr =
6.6250+ 6.5
2

= 6.5625

f(Xl)f(Xr) = -0.33105 < 0

|6. 56256.6250
|100=0.95
6.5625

Iteration (5):
Set Xu = Xr = 6.5625, Xl = 6.5, Xr =
6. 5625+6.5
2

= 6.5313

f(Xl)f(Xr) = 0.11646 > 0

6.53136.5625
=
100=0. 48
6.5313
Iteration (6):
Set Xl = Xr = 6.5313, Xu = 6.5625, Xr =
6.5625+ 6.5313
2

= 6.5469

f(Xl)f(Xr) = -0.02218 < 0

|6.54696.5313
|100=0. 24
6.5469

Therefore, X
SOURCE CODE

6.5469

package bisec;
import static java.lang.Math.abs;
import javax.swing.JOptionPane;
public class Bisec {
public static void main(String[] args) {
String Xup = JOptionPane.showInputDialog (null,"f(x)=x^2+6x-82\n\nEnter
The Upper Subinterval X:" , "Chapter 5:Bisection Method" ,
JOptionPane.PLAIN_MESSAGE);
String Xlow = JOptionPane.showInputDialog (null, "f(x)=x^2+6x-82\n\nEnter
The Lower Subinterval X:" , "Chapter 5:Bisection Method",
JOptionPane.PLAIN_MESSAGE);
double Xu = Double.parseDouble(Xup);
double Xl = Double.parseDouble(Xlow);
double Xr = getXr(Xu,Xl);
String X = String.format("Xu: %.4f %nXl: %.4f %nXr: %4f", Xu, Xl, Xr);
double result = f(Xl, Xr);
String f = null;
if (result>0){Xl=Xr; f = String.format("%nf(Xl)f(Xr) = %.5f>0", result);}
else if (result<0) {Xu=Xr; f = String.format("%nf(Xl)f(Xr) = %.5f<0", result);}
JOptionPane.showMessageDialog (null, X+f , "Iteration 1:",
JOptionPane.INFORMATION_MESSAGE);
double Ea=100;
for(int Iteration=2; Ea>0.3; Iteration++){
String iteration = String.format("Iteration" +Iteration+":");
double Xrnew = getXr(Xu,Xl);
X = String.format("Xu: %.4f %nXl: %.4f%nXr: %.4f", Xu, Xl, Xrnew);
Ea = error(Xrnew, Xr);
String Aerror = String.format("%nApproximation error: %.2f",Ea)+"%";
result = f(Xl, Xrnew);
if (result>0){Xl=Xrnew; f = String.format("%nf(Xl)f(Xr) = %.5f>0", result);}
else
if (result<0){Xu=Xrnew; f = String.format("%nf(Xl)f(Xr) = %.5f<0", result);}
Xr = Xrnew;

JOptionPane.showMessageDialog (null, X+Aerror+f, iteration,


JOptionPane.INFORMATION_MESSAGE);
}
}
public static double getXr(double Xu, double Xl){
double Xr=(Xu+Xl)/2;
return Xr;
}
public static double f(double Xl, double Xr){
//result of the function f(x)=x^2+4x-35 when f(Xl)
double f = Math.pow(Xl,2)+(6*Xl)-82;
//result of the function f(x)=x^2-2 when f(Xr)
double f1 =Math.pow(Xr,2)+(6*Xr)-82;
double result =f*f1;
return result;
}
public static double error(double Xrnew, double Xr){
double Ea = abs((Xrnew-Xr)/Xrnew)*100;
return Ea;
}
}

SCREENSHOTS

CONCLUSION
Before proceeding with the proper procedures using the Bisection
Method, we should first analyze the problem. After analyzing the problem, we
have to come up with our function. For this instance, this simple problem
involving vector forces can be solved directly using the Pythagorean
Theorem. The root from the analytical solution can be the basis for our
numerical solution. Although Bisection Method is a longer process compared

to other process, it still provides a neat error analysis which makes it suitable
for engineering applications. Therefore, Bisection Method is an effective way
of solving engineering problems.

You might also like