Численные методы решения прикладных задач - page 86

86
Решение в редакторе Visual Basic
Код программы Visual Basic:
Function F(ByVal x As Double)
F = x ^ 4 + 2 * x ^ 3 - x - 1
End Function
Function F1(ByVal x As Double)
F1 = 4 * x ^ 3 + 6 * x ^ 2 - 1
End Function
Private Sub CommandButton1_Click()
ActiveSheet.Cells(10, 1).Value = "Корень на выбранном промежутке не найден"
xn = ActiveSheet.Cells(3, 5).Value
xk = ActiveSheet.Cells(4, 5).Value
xh = ActiveSheet.Cells(5, 5).Value
x = xn
While x <= xk
F11 = F(x)
F12 = F(x + xh)
If F11 * F12 < 0 Then
ActiveSheet.Cells(10, 1).Value = "Корень принадлежит промежутку (" & Str(x)
& ";" & Str(x + xh) & ")"
A = x
an = x
B = x + xh
End If
x = x + xh
Wend
k = 0
e = ActiveSheet.Cells(6, 5).Value
ActiveSheet.Cells(13, 1).Value = ""
While Abs(F(x)) > e
x = (A + B) / 2
If F(A) * F(x) < 0 Then
B = x
Else
A = x
End If
k = k + 1
Wend
ActiveSheet.Cells(13, 1).Value = "Корень =" & Str(x) & " c точностью" & Str(e) & "
вычислена " & Str(k) & " итерации"
k = 0
x = an
I...,76,77,78,79,80,81,82,83,84,85 87,88,89,90,91,92,93,94,95,96,...284
Powered by FlippingBook