สรุป Numerical Mr. KHIM LAGN Code 50052498
Code for program Dim count As Integer Dim mk As Double Private Sub CommandButton1_Click() Dim a As Double Dim b As Double Dim tol As Double Dim m As Integer Dim result As Double Dim year As Integer m = Val(Range("g4").Value) count = Not count
If count Then For i = 2 To (m + 1) Step 1 a = Val(Range("g1").Value) b = Val(Range("g2").Value) tol = Val(Range("g3").Value) Cells(i, 1) = (i - 1) year = (i - 1) result = regula(a, b, tol, year) Cells(i, 2).Value = result Next i CommandButton1.Caption = "ź" Else Range("A2", "D1501").ClearContents Cells(5, 6) = Clear CommandButton1.Caption = "áÊ´§" End If End Sub Private Function f(x As Double, m As Integer) As Double f = (((288000 / x) * (1 - ((1 + (x / 12)) ^ ((-12) * m)))) - 3000000) End Function Private Function regula(a As Double, b As Double, tol As Double, year As Integer) As Double Dim c As Double If a = 0 Then a = 0.01 End If c = b - ((f(b, year)) * ((b - a) / ((f(b, year)) - (f(a, year))))) Do While Abs(f(c, year)) > tol If (f(a, year) * (f(c, year))) > 0 Then
a=c Else b=c End If c = b - ((f(b, year)) * ((b - a) / ((f(b, year)) - (f(a, year))))) Loop regula = c End Function