bisection coding write, Cheat Sheet of Mechanics

bisection coding write good reference

Typology: Cheat Sheet

2023/2024

Uploaded on 06/21/2024

or-or-erica-3
or-or-erica-3 🇰🇷

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Option Explicit
Sub Bisection_Method()
Dim imax As Integer, iter As Integer
Dim xl As Single, xu As Single, xr As Single, es As Single, ea As Single
Worksheets("Bisection").Activate
xl = Range("B4")
xu = Range("B5")
es = Range("B6")
imax = Range("B7")
Range("A10:H100").ClearContents
Range("A10") = "반복횟수"
Range("B10") = "xl"
Range("C10") = "f(xl)"
Range("D10") = "xu"
Range("E10") = "f(xu)"
Range("F10") = "xr"
Range("G10") = "f(xr)"
Range("H10") = "error"
If f(xl) * f(xu) < 0 Then
Call Bisect(xl, xu, xr, es, ea, iter, imax)
pf3
pf4

Partial preview of the text

Download bisection coding write and more Cheat Sheet Mechanics in PDF only on Docsity!

Option Explicit Sub Bisection_Method() Dim imax As Integer, iter As Integer Dim xl As Single, xu As Single, xr As Single, es As Single, ea As Single Worksheets("Bisection").Activate xl = Range("B4") xu = Range("B5") es = Range("B6") imax = Range("B7") Range("A10:H100").ClearContents Range("A10") = "반복횟수" Range("B10") = "xl" Range("C10") = "f(xl)" Range("D10") = "xu" Range("E10") = "f(xu)" Range("F10") = "xr" Range("G10") = "f(xr)" Range("H10") = "error" If f(xl) * f(xu) < 0 Then Call Bisect(xl, xu, xr, es, ea, iter, imax)

Else MsgBox "No sign change between initial guesses" End If End Sub Sub Bisect(xl, xu, xr, es, ea, iter, imax) Dim xrold As Single, test As Single iter = 0 Do xrold = xr xr = (xl + xu) / 2 iter = iter + 1 If xr <> 0 Then ea = Abs((xr - xrold) / xr) * 100 End If test = f(xl) * f(xr) If test < 0 Then

f = 9.8 * 68.1 / c * (1 - Exp(-(c / 68.1) * 10)) - 40 End Function