Write a SUB PROCEDURE in VBA code to implement BISECTION met
Solution
\'declare variables
Dim n As Double
Dim o As Double
Dim p As Double
Dim m As Double
Dim expression As Double
Sub retrieveinputs()
\'getting value from excel sheet
m = Cells(4, 3)
n = Cells(5, 3)
o = Cells(6, 3)
p = (n + o) / 2
expression = Cells(8, 3)
End Sub
Sub getroot()
Dim fm As Double
Dim fn As Double
Dim fo As Double
Dim k As Integer
Dim n As Integer
n = Cells(9, 3)
Do Until k <= n
k = Cells(10, 3)
Do Until Abs(fm) <= m
fn = 2 * (n - 2) ^ 2 - expression ^ n
fo = 2 * (o - 2) ^ 2 - expression ^ o
fm = 2 * (p - 2) ^ 2 - expression ^ p
p = Cells(2, 4)
fn = Cells(2, 5)
fo = Cells(2, 6)
fm = Cells(2, 7)
If fm * fn < 0 Then
o = p
End If
If fm * fo < 0 Then
n = p
End If
Loop
k = k + 1
Loop
End Sub
