


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
bisection coding write good reference
Typology: Cheat Sheet
1 / 4
This page cannot be seen from the preview
Don't miss anything!



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