Word / вычмат1
.docSub na_tri_otrezka()
Dim a!, b!, eps!, Z!, x1!, x2!, x3!, x4!, x!
Dim f2!, f3!, k%
a = Cells(1, 2)
b = Cells(2, 2)
eps = Cells(3, 2)
x1 = a: x4 = b: Z = 1 / 3
k = 0
Do
Cells(2 + k, 6) = x1
Cells(2 + k, 9) = x4
Cells(2 + k, 12) = Abs(x4 - x1)
x2 = x1 + Z * (x4 - x1)
Cells(2 + k, 7) = x2
x3 = x4 - Z * (x4 - x1)
Cells(2 + k, 8) = x3
f2 = f(x2): f3 = f(x3)
Cells(2 + k, 10) = f(x2): Cells(2 + k, 11) = f(x3)
If f2 < f3 Then x4 = x3
If f2 > f3 Then x1 = x2
k = k + 1
Cells(1 + k, 5) = k
Loop Until Abs(x4 - x1) <= 2 * eps
x = (x1 + x4) / 2
Cells(4, 2) = x
Cells(5, 2) = f(x)
End Sub
Function f(x!)
f = -6.302 + 13.759 * x + 7.843 * x ^ 2 + x ^ 3
End Function
Sub na_popalam()
Dim a!, b!, eps!, x1!, x2!, x3!, x4!, x!
Dim f2!, f3!, k%
a = Cells(1, 2)
b = Cells(2, 2)
eps = Cells(3, 2)
x1 = a: x4 = b
k = 0
Do
Cells(2 + k, 6) = x1
Cells(2 + k, 9) = x4
Cells(2 + k, 12) = Abs(x4 - x1)
x2 = (x4 + x1) / 2: x3 = x2 + (x4 - x1) / 100
f2 = f(x2): f3 = f(x3)
Cells(2 + k, 7) = x2
Cells(2 + k, 8) = x3
Cells(2 + k, 10) = f(x2): Cells(2 + k, 11) = f(x3)
If f2 < f3 Then x4 = x3
If f2 > f3 Then x1 = x2
k = k + 1
Cells(1 + k, 5) = k
Loop Until Abs(x4 - x1) <= 2 * eps
x = (x1 + x4) / 2
Cells(4, 2) = x
Cells(5, 2) = f(x)
End Sub
Function f(x!)
f = -6.302 + 13.759 * x + 7.843 * x ^ 2 + x ^ 3
End Function
Sub zolotoe_sechenie()
Dim a!, b!, eps!, Z!, x1!, x2!, x3!, x4!, x!
Dim f2!, f3!, k%
a = Cells(1, 2)
b = Cells(2, 2)
eps = Cells(3, 2)
x1 = a: x4 = b: Z = (3 - Sqr(5)) / 2
x2 = x1 + Z * (x4 - x1): x3 = x4 - Z * (x4 - x1)
f2 = f(x2): f3 = f(x3)
k = 0
Do
Cells(2 + k, 6) = x1
Cells(2 + k, 9) = x4
Cells(2 + k, 12) = Abs(x4 - x1)
Cells(2 + k, 7) = x2
Cells(2 + k, 8) = x3
Cells(2 + k, 10) = f(x2)
Cells(2 + k, 11) = f(x3)
If f2 < f3 Then
x4 = x3: x3 = x2: f3 = f2
x2 = x1 + Z * (x4 - x1): f2 = f(x2)
Else
x1 = x2: x2 = x3: f2 = f3
x3 = x4 - Z * (x4 - x1): f3 = f(x3)
End If
k = k + 1
Cells(1 + k, 5) = k
Loop Until Abs(x4 - x1) <= 2 * eps
x = (x1 + x4) / 2
Cells(4, 2) = x
Cells(5, 2) = f(x)
End Sub
Function f(x!)
f = -6.302 + 13.759 * x + 7.843 * x ^ 2 + x ^ 3
End Function