Численные методы интегрирования - 2002 / all_in_one
.docDim a!, b!
Function My_fun(x!) As Single
My_fun = x ^ 3 + 30 * x ^ 2 + 291 * x + 910
End Function
Function Dfun(x!) As Single
Dfun = 3 * x ^ 2 + 60 * x + 291
End Function
Sub method_kas()
Dim x!
Cells(1, 1) = "a": Cells(1, 2) = "b": Cells(1, 3) = "f(a)": Cells(1, 4) = "f(b)"
a = Cells(2, 1): b = Cells(2, 2): Cells(2, 3) = My_fun(a!): Cells(2, 4) = My_fun(b!)
If My_fun(a) * My_fun(b) > 0 Then b = a
Cells(3, 1) = "i": Cells(3, 2) = "b": Cells(3, 3) = "f(b)": Cells(3, 4) = "f '(b)": Cells(3, 5) = "x": Cells(3, 6) = "f(x)"
i = 0
GoTo 10
Do
b = x
10
x = b - My_fun(b!) / Dfun(b!)
Cells(i + 4, 1) = i: Cells(i + 4, 2) = b: Cells(i + 4, 3) = My_fun(b!): Cells(i + 4, 4) = Dfun(b!): Cells(i + 4, 5) = x: Cells(i + 4, 6) = My_fun(x!)
i = i + 1
Loop While Abs(b - x) > 0.05
End Sub
Sub polov_del()
Dim x!
Cells(1, 1) = "i": Cells(1, 2) = "a": Cells(1, 3) = "b": Cells(1, 4) = "x": Cells(1, 5) = "f(x)": Cells(1, 6) = "f(a)": Cells(1, 7) = "f(b)": Cells(1, 8) = "abs(a - b)"
a = Cells(2, 2): b = Cells(2, 3)
i = 0
GoTo 10
Do
If My_fun(x!) * My_fun(a!) < 0 Then b = x
If My_fun(x!) * My_fun(a!) > 0 Then a = x
10
x = (a + b) / 2
Cells(i + 2, 1) = i: Cells(i + 2, 2) = a: Cells(i + 2, 3) = b: Cells(i + 2, 4) = x: Cells(i + 2, 5) = My_fun(x!): Cells(i + 2, 6) = My_fun(a!): Cells(i + 2, 7) = My_fun(b!): Cells(i + 2, 8) = Abs(a - b)
i = i + 1
Loop While Abs(a - b) > 0.05
End Sub
Sub method_sec()
Dim x!
Cells(1, 1) = "i": Cells(1, 2) = "a": Cells(1, 3) = "b": Cells(1, 4) = "f(a)": Cells(1, 5) = "f(b)": Cells(1, 6) = "x": Cells(1, 7) = "f(x)": Cells(1, 8) = "abs(x-a)"
a = Cells(2, 2): b = Cells(2, 3)
i = 0
GoTo 10
Do
If My_fun(x!) * My_fun(a!) < 0 Then b = x
If My_fun(x!) * My_fun(a!) > 0 Then a = x
10
x = (a * My_fun(b) - b * My_fun(a)) / (My_fun(b) - My_fun(a))
Cells(i + 2, 1) = i: Cells(i + 2, 2) = a: Cells(i + 2, 3) = b: Cells(i + 2, 4) = My_fun(a!): Cells(i + 2, 5) = My_fun(b!): Cells(i + 2, 6) = x: Cells(i + 2, 7) = My_fun(x!): Cells(i + 2, 8) = Abs(x - a)
i = i + 1
Loop While Abs(x - a) > 0.05
End Sub
Sub method_delna3chasti()
Dim x1!, x4!
Cells(1, 1) = "i": Cells(1, 2) = "x1": Cells(1, 3) = "x2": Cells(1, 4) = "x3": Cells(1, 5) = "x4": Cells(1, 6) = "f(2)": Cells(1, 7) = "f(3)": Cells(1, 8) = "abs(x4-x1)"
x1 = Cells(2, 2): x4 = Cells(2, 5)
i = 0
GoTo 10
Do
If Abs(My_fun(x2!)) > Abs(My_fun(x3!)) Then x1 = x2
If Abs(My_fun(x2!)) < Abs(My_fun(x3!)) Then x4 = x3
10
x2 = x1 + (x4 - x1) / 3
x3 = x4 - (x4 - x1) / 3
Cells(i + 2, 1) = i: Cells(i + 2, 2) = x1: Cells(i + 2, 3) = x2: Cells(i + 2, 4) = x3: Cells(i + 2, 5) = x4: Cells(i + 2, 6) = My_fun(x2!): Cells(i + 2, 7) = My_fun(x3!): Cells(i + 2, 8) = Abs(x4 - x1)
i = i + 1
Loop While Abs(x4 - x1) > 0.05
End Sub
Sub method_goldcecheniya()
Dim x1!, x4!
Cells(1, 1) = "i": Cells(1, 2) = "x1": Cells(1, 3) = "x2": Cells(1, 4) = "x3": Cells(1, 5) = "x4": Cells(1, 6) = "f(2)": Cells(1, 7) = "f(3)": Cells(1, 8) = "abs(x4-x1)"
x1 = Cells(2, 2): x4 = Cells(2, 5)
i = 0
GoTo 10
Do
If Abs(My_fun(x2!)) > Abs(My_fun(x3!)) Then x1 = x2
If Abs(My_fun(x2!)) < Abs(My_fun(x3!)) Then x4 = x3
10
x2 = x1 + (x4 - x1) / 3
x3 = x4 - (x4 - x1) / 3
Cells(i + 2, 1) = i: Cells(i + 2, 2) = x1: Cells(i + 2, 3) = x2: Cells(i + 2, 4) = x3: Cells(i + 2, 5) = x4
Cells(i + 2, 6) = My_fun(x2!): Cells(i + 2, 7) = My_fun(x3!): Cells(i + 2, 8) = Abs(x4 - x1)
i = i + 1
Loop While Abs(x4 - x1) > 0.05
End Sub