Columban College, Inc
COLLEGE OF ENGINEERING
Rizal Street, Barrio Barretto, Olongapo City 2200 Philippines
Tel No. 222-9360 Local 102 and 222-9361
PACUCOA ACCREDITED
NUMERICAL SOLUTION TO CE PROBLEMS
BISECTION METHOD
FALSE-POSITION METHOD
SUBMITTED BY:
DE JESUS, PHOEBE KATE S.
SUBMITTED TO:
ENGR. EDWIN GRATE
Equation: f(x) = 5 + 13x + 7x^2 - 41x^3 [Link]
Xu = 0.5; Xl = 1
Tolerance = 5 % ' Display given values and equation
Range("A1").Value = "Bisection
Method"
BISECTION METHOD VPA
PROGRAMMING Range("A2").Value = "Equation: f(x) =
5 + 13x + 7x^2 - 41x^3"
Range("A3").Value = "Xl:"
Range("B3").Value = Xl
Range("A4").Value = "Xu:"
Range("B4").Value = Xu
Range("A5").Value = "Tolerance (%):"
Range("B5").Value = Tolerance
Sub BisectionMethod_NewEquation()
Dim Xl As Double, Xu As Double, Xr
As Double ' Table headers
Dim fXl As Double, fXu As Double, Range("A7").Value = "Iter"
fXr As Double
Range("B7").Value = "Xl"
Dim Ea As Double, Tolerance As
Range("C7").Value = "Xu"
Double
Range("D7").Value = "Xr"
Dim Iter As Integer, MaxIter As Integer
Range("E7").Value = "f(Xr)"
Dim OldXr As Double
Range("F7").Value = "Ea (%)"
' Given values
' Function values at Xl and Xu
Xl = 1
fXl = 5 + 13 * Xl + 7 * Xl ^ 2 - 41 * Xl
Xu = 0.5
^3
Tolerance = 5
fXu = 5 + 13 * Xu + 7 * Xu ^ 2 - 41 *
MaxIter = 50 Xu ^ 3
Ea = 100
Iter = 0 ' Check if root is bracketed
OldXr = 0 If fXl * fXu > 0 Then
MsgBox "No root in this interval"
' Clear old output Exit Sub
End If Xu = Xr
fXu = fXr
' Iterations (at least 5) ElseIf fXl * fXr > 0 Then
Do While (Ea > Tolerance Or Iter < 5) Xl = Xr
And Iter < MaxIter
fXl = fXr
Iter = Iter + 1
Else
Exit Do
' Bisection formula
End If
Xr = (Xl + Xu) / 2
Loop
fXr = 5 + 13 * Xr + 7 * Xr ^ 2 - 41 *
Xr ^ 3
MsgBox "Bisection Method Complete.
Root ≈ " & Xr
' Approximate error
End Sub
If Iter > 1 Then
Ea = Abs((Xr - OldXr) / Xr) * 100
Else
FALSE-POSITION METHOD VPA
Ea = 100 PROGRAMMING
End If
OldXr = Xr
' Output table row
Range("A" & Iter + 7).Value = Iter
Range("B" & Iter + 7).Value = Xl
Range("C" & Iter + 7).Value = Xu Sub FalsePosition_NewEquation()
Range("D" & Iter + 7).Value = Xr Dim Xl As Double, Xu As Double, Xr As
Double
Range("E" & Iter + 7).Value = fXr
If Iter > 1 Then Range("F" & Iter + Dim fXl As Double, fXu As Double, fXr As
7).Value = Ea Double
Dim Ea As Double, Tolerance As Double
' Update bounds Dim Iter As Integer, MaxIter As Integer
If fXl * fXr < 0 Then Dim OldXr As Double
Range("E7").Value = "f(Xr)"
' Given values Range("F7").Value = "Ea (%)"
Xl = 1
Xu = 0.5 ' Function values at Xl and Xu
Tolerance = 5 fXl = 5 + 13 * Xl + 7 * Xl ^ 2 - 41 * Xl ^ 3
MaxIter = 50 fXu = 5 + 13 * Xu + 7 * Xu ^ 2 - 41 * Xu ^
3
Ea = 100
Iter = 0
' Check if root is bracketed
OldXr = 0
If fXl * fXu > 0 Then
MsgBox "No root in this interval"
' Clear old output
Exit Sub
[Link]
End If
' Display given values and equation
' Iterations (at least 5)
Range("A1").Value = "False Position
Method" Do While (Ea > Tolerance Or Iter < 5)
And Iter < MaxIter
Range("A2").Value = "Equation: f(x) = 5
+ 13x + 7x^2 - 41x^3" Iter = Iter + 1
Range("A3").Value = "Xl:"
Range("B3").Value = Xl ' False position formula
Range("A4").Value = "Xu:" Xr = Xu - (fXu * (Xl - Xu)) / (fXl - fXu)
Range("B4").Value = Xu fXr = 5 + 13 * Xr + 7 * Xr ^ 2 - 41 * Xr ^
3
Range("A5").Value = "Tolerance (%):"
Range("B5").Value = Tolerance
' Approximate error
If Iter > 1 Then
' Table headers
Ea = Abs((Xr - OldXr) / Xr) * 100
Range("A7").Value = "Iter"
Else
Range("B7").Value = "Xl"
Ea = 100
Range("C7").Value = "Xu"
End If
Range("D7").Value = "Xr"
OldXr = Xr
' Output table row
Range("A" & Iter + 7).Value = Iter
Range("B" & Iter + 7).Value = Xl
Range("C" & Iter + 7).Value = Xu
Range("D" & Iter + 7).Value = Xr
Range("E" & Iter + 7).Value = fXr
If Iter > 1 Then Range("F" & Iter +
7).Value = Ea
' Update bounds
If fXl * fXr < 0 Then
Xu = Xr
fXu = fXr
ElseIf fXl * fXr > 0 Then
Xl = Xr
fXl = fXr
Else
Exit Do
End If
Loop
MsgBox "False Position Method
Complete. Root ≈ " & Xr
End Sub