0% found this document useful (0 votes)
10 views13 pages

Bisection Workbook NM A1[1]

The document outlines a numerical methods assignment by Bimal Poudel, detailing a VBA implementation for calculating shear force (Vu) and applying the Bisection method to find roots of polynomial functions. It includes a structured approach with algorithms, flowcharts, and code snippets for both calculations. The outputs demonstrate the results of the calculations and the Bisection method iterations, providing a comprehensive overview of the implementation process.

Uploaded by

bimal2414s.mstr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views13 pages

Bisection Workbook NM A1[1]

The document outlines a numerical methods assignment by Bimal Poudel, detailing a VBA implementation for calculating shear force (Vu) and applying the Bisection method to find roots of polynomial functions. It includes a structured approach with algorithms, flowcharts, and code snippets for both calculations. The outputs demonstrate the results of the calculations and the Bisection method iterations, providing a comprehensive overview of the implementation process.

Uploaded by

bimal2414s.mstr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Numerical Methods

Assignment

Bimal Poudel
Table of Contents

Function of Structure formula..........................................................................1


Output..........................................................................................................3
Report for VBA Implementation.......................................................................4
Algorithm......................................................................................................4
Flowchart......................................................................................................6
Code.............................................................................................................7
Output........................................................................................................11
Function of Structure formula
Sub Calculate Vu And ShowInSheet()

Dim Fy As Double

Dim Asv As Double

Dim d As Double

Dim Sv As Double

Dim Vu As Double

Dim ws As Worksheet

Dim startRow As Integer

' Create or use active sheet

Set ws = ActiveSheet

startRow = 2 ' Leave row 1 for the title

' Get user input values

Fy = Val(InputBox("Enter yield strength of steel Fy (N/mm²):", "Input Fy"))

Asv = Val(InputBox("Enter area of shear reinforcement Asv (mm²):", "Input


Asv"))

d = Val(InputBox("Enter effective depth d (mm):", "Input d"))

Sv = Val(InputBox("Enter spacing of stirrups Sv (mm):", "Input Sv"))

' Validate inputs

If Fy <= 0 Or Asv <= 0 Or d <= 0 Or Sv <= 0 Then

MsgBox "All values must be positive and non-zero.", vbCritical

Exit Sub

End If

1
' Calculate Vu

Vu = 0.87 * Fy * Asv * d / Sv

' Output heading

With ws

.Cells(1, 1).Value = "Vu Calculation using: Vu = 0.87 * Fy * Asv * d / Sv"

.Range("A1:E1").Merge

.Range("A1").Font.Bold = True

.Range("A1").Font.Size = 14

.Range("A1").HorizontalAlignment = xlCenter

' Output table headers

.Cells(startRow, 1).Value = "Fy (N/mm²)"

.Cells(startRow, 2).Value = "Asv (mm²)"

.Cells(startRow, 3).Value = "d (mm)"

.Cells(startRow, 4).Value = "Sv (mm)"

.Cells(startRow, 5).Value = "Vu (N)"

.Range("A" & startRow & ":E" & startRow).Font.Bold = True

' Output values in next row

.Cells(startRow + 1, 1).Value = Fy

.Cells(startRow + 1, 2).Value = Asv

.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

MsgBox "Vu calculated and shown in the sheet!", vbInformation

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 Interval [a, b] such that f(a)*f(b) < 0

o Tolerance tol

o Maximum number of iterations maxIter

3. Check: If f(a) * f(b) > 0

o Print "Invalid interval. No sign change."

o Stop

4. Initialize:

o Create a new Excel workbook named "Bisection_Workbook.xlsx"

o Add a worksheet named "Bisection_Log"

o Write heading: "Table prepared by Samunnat Bhandari"

o Write column headers

5. Loop for i = 1 to maxIter:

o Compute midpoint c = (a + b) / 2

o Compute f(c)

4
o Compute error = |b - a| / 2

o Log i, a, b, c, f(c), and error in the worksheet

6. Check Convergence:

o If |f(c)| < tol or error < tol:

 Write: Root found at x = c

 Write: Number of iterations = i

 Exit loop

7. Update Interval:

o If f(a) * f(c) < 0: set b = c

o Else: set a = c

8. End Loop

9. Save Workbook: as "Bisection_Workbook.xlsx"

10. End

5
Flowchart

Code

6
' Define the polynomial function here

Function f(x As Double) As Double

' Example: f(x) = x^3 - x - 2

f=x^3-x-2

End Function

Sub BisectionMethod_CreateWorkbook()

Dim a As Double, b As Double, c As Double

Dim tol As Double

Dim maxIter As Integer

Dim i As Integer

Dim errorEstimate As Double

Dim wb As Workbook

Dim ws As Worksheet

Dim filePath As String

Dim finalRow As Long

' === INITIAL PARAMETERS ===

a=1 ' Lower bound of interval

b=2 ' Upper bound of interval

tol = 0.0001 ' Tolerance for stopping

maxIter = 100 ' Max number of iterations

' === CHECK INITIAL CONDITION ===

If f(a) * f(b) > 0 Then

7
MsgBox "f(a) and f(b) must have opposite signs. No root guaranteed.",
vbCritical

Exit Sub

End If

' === CREATE NEW WORKBOOK ===

Set wb = Workbooks.Add

Set ws = wb.Sheets(1)

ws.Name = "Bisection_Log"

' === WRITE HEADER ===

With ws

.Cells(1, 1).Value = "Table prepared by Samunnat Bhandari"

.Range("A1:F1").Merge

.Range("A1").Font.Bold = True

.Range("A1").Font.Size = 14

.Range("A1").HorizontalAlignment = xlCenter

' Column headers in row 3

.Cells(3, 1).Value = "Iteration"

.Cells(3, 2).Value = "a"

.Cells(3, 3).Value = "b"

.Cells(3, 4).Value = "c (Midpoint)"

.Cells(3, 5).Value = "f(c)"

.Cells(3, 6).Value = "Error Estimate"

.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

' Log the current iteration (starting from row 4)

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

.Cells(i + 3, 5).Value = f(c)

.Cells(i + 3, 6).Value = errorEstimate

End With

If Abs(f(c)) < tol Or errorEstimate < tol Then

Exit For

End If

If f(a) * f(c) < 0 Then

b=c

Else

a=c

End If

Next i

9
' === WRITE FINAL SUMMARY BELOW THE TABLE ===

finalRow = i + 5

With ws

.Cells(finalRow, 1).Value = "Root found at x ="

.Cells(finalRow, 2).Value = c

.Cells(finalRow + 1, 1).Value = "Number of iterations ="

.Cells(finalRow + 1, 2).Value = i

.Range("A" & finalRow & ":B" & finalRow + 1).Font.Bold = True

End With

' === SAVE WORKBOOK ===

filePath = Application.DefaultFilePath & "\Bisection_Workbook.xlsx"

Application.DisplayAlerts = False

wb.SaveAs Filename:=filePath

Application.DisplayAlerts = True

MsgBox "Bisection table and result saved to: " & filePath, vbInformation

End Sub

10
Output
TablepreparedbySamunnatBhandari

Iteration a b c (Midpoint) f(c) ErrorEstimate


1 1 2 1.5 -0.125 0.5
2 1.5 2 1.75 1.609375 0.25
3 1.5 1.75 1.625 0.6660156 0.125
4 1.5 1.625 1.5625 0.2521973 0.0625
5 1.5 1.5625 1.53125 0.0591125 0.03125
6 1.5 1.53125 1.515625 -0.0340538 0.015625
7 1.515625 1.53125 1.5234375 0.0122504 0.0078125
8 1.515625 1.5234375 1.51953125 -0.0109712 0.00390625
9 1.51953125 1.5234375 1.521484375 0.0006222 0.001953125
10 1.51953125 1.52148438 1.520507813 -0.0051789 0.000976563
11 1.52050781 1.52148438 1.520996094 -0.0022794 0.000488281
12 1.52099609 1.52148438 1.521240234 -0.0008289 0.000244141
13 1.52124023 1.52148438 1.521362305 -0.0001034 0.00012207
14 1.5213623 1.52148438 1.52142334 0.0002594 6.10352E-05

Rootfoundatx= 1.52142334
Numberofiterations= 14

11

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy