Bisection Workbook NM A1[1]
Bisection Workbook NM A1[1]
Assignment
Bimal Poudel
Table of Contents
Dim Fy As Double
Dim d As Double
Dim Sv As Double
Dim Vu As Double
Dim ws As Worksheet
Set ws = ActiveSheet
Exit Sub
End If
1
' Calculate Vu
Vu = 0.87 * Fy * Asv * d / Sv
With ws
.Range("A1:E1").Merge
.Range("A1").Font.Bold = True
.Range("A1").Font.Size = 14
.Range("A1").HorizontalAlignment = xlCenter
.Cells(startRow + 1, 1).Value = Fy
.Cells(startRow + 1, 3).Value = d
.Cells(startRow + 1, 4).Value = Sv
.Cells(startRow + 1, 5).Value = Vu
2
' Autofit columns for readability
.Columns("A:E").AutoFit
End With
End Sub
Output
VuCalculationusing: Vu=0.87* Fy* Asv* d/ Sv
Fy(N/mm²) Asv(mm²) d(mm) Sv(mm) Vu(N)
415 100 500 150 120350
3
Report for VBA Implementation
Write the Report for VBA implementation of Bisection method with
Algorithm ,Flowchart, VBA code.
Algorithm
Objective: To find a root of a polynomial function f(x) using the Bisection
Method and store the results in a new Excel workbook.
Step-by-Step Algorithm
1. Start
2. Input:
o Function f(x)
o Tolerance tol
o Stop
4. Initialize:
o Compute midpoint c = (a + b) / 2
o Compute f(c)
4
o Compute error = |b - a| / 2
6. Check Convergence:
Exit loop
7. Update Interval:
o Else: set a = c
8. End Loop
10. End
5
Flowchart
Code
6
' Define the polynomial function here
f=x^3-x-2
End Function
Sub BisectionMethod_CreateWorkbook()
Dim i As Integer
Dim wb As Workbook
Dim ws As Worksheet
7
MsgBox "f(a) and f(b) must have opposite signs. No root guaranteed.",
vbCritical
Exit Sub
End If
Set wb = Workbooks.Add
Set ws = wb.Sheets(1)
ws.Name = "Bisection_Log"
With ws
.Range("A1:F1").Merge
.Range("A1").Font.Bold = True
.Range("A1").Font.Size = 14
.Range("A1").HorizontalAlignment = xlCenter
.Range("A3:F3").Font.Bold = True
End With
8
' === BISECTION METHOD LOOP ===
For i = 1 To maxIter
c = (a + b) / 2
errorEstimate = Abs(b - a) / 2
With ws
.Cells(i + 3, 1).Value = i
.Cells(i + 3, 2).Value = a
.Cells(i + 3, 3).Value = b
.Cells(i + 3, 4).Value = c
End With
Exit For
End If
b=c
Else
a=c
End If
Next i
9
' === WRITE FINAL SUMMARY BELOW THE TABLE ===
finalRow = i + 5
With ws
.Cells(finalRow, 2).Value = c
.Cells(finalRow + 1, 2).Value = i
End With
Application.DisplayAlerts = False
wb.SaveAs Filename:=filePath
Application.DisplayAlerts = True
MsgBox "Bisection table and result saved to: " & filePath, vbInformation
End Sub
10
Output
TablepreparedbySamunnatBhandari
Rootfoundatx= 1.52142334
Numberofiterations= 14
11