Решить нелинейное уравнение и построить график - VB
Формулировка задачи:
Доброго времени суток.
Есть такое задание: Решить нелинейное уравнение и построить график Ln(x)-x+1.8=0 [2;3]. VB знаю не очень хорошо.
Мат.Решение:
Нелинейное уравнение решил
Объясните/помогите: как мне построить график с выводом результата итерации
График Excele:
Спойлер
Листинг программы
- Dim x0 As Double, x1 As Double
- Private Sub Command1_Click()
- Dim x0 As Double, x1 As Double, a As Double, b As Double, e As Double
- Dim iteraz As Integer, s As String, s1 As String
- Me.Height = 7800
- x1 = InputBox("Введите приближённое(1) значение X=", , 2)
- e = InputBox("Введите точность(0.0001) e=", , 0.0001)
- iteraz = 0
- Do
- iteraz = iteraz + 1
- x0 = x1
- x1 = fun(x0)
- Picture1.Print Format(x0, "##.000")
- Picture2.Print Format(x1, "##.000")
- Loop Until (Abs(x1 - x0) <= e)
- s = s & "Вычисленное значение корня:" & x1 & vbCrLf
- s = s & "Число итераций:" & iteraz
- Picture3.Print Format(s, "##.000")
- End Sub
- Private Function fun(X As Double) As Double
- fun = Log(X) + 1.8
- End Function
Решение задачи: «Решить нелинейное уравнение и построить график»
textual
Листинг программы
- Option Explicit
- Private Sub Command1_Click()
- Dim x As Double, x0 As Double, x1 As Double, a As Double, b As Double, e As Double
- Dim iteraz As Integer, s As String, s1 As String, i As Integer
- Me.Height = 7800
- x1 = InputBox("Введите приближённое(1) значение X=", , 2)
- e = InputBox("Введите точность(0.0001) e=", , 0.0001)
- Picture1.Cls: Picture2.Cls: Picture3.Cls: Picture4.Cls
- Picture4.AutoRedraw = True: Picture4.FillStyle = 0
- iteraz = 0: x = x1
- Do
- iteraz = iteraz + 1
- x0 = x1
- x1 = fun(x0)
- Picture1.Print Format(x0, "##.00000")
- Picture2.Print Format(x1, "##.00000")
- Loop Until (Abs(x1 - x0) <= e)
- Picture4.DrawStyle = 0: Picture4.DrawWidth = 2
- Picture4.Scale (-1, x + 2)-(iteraz + 1, -1)
- Picture4.Line (-1, 0)-(iteraz + 1, 0), vbBlue
- Picture4.Line (0, -1)-(0, x + 2), vbBlue
- For i = 0 To iteraz
- Picture4.DrawStyle = 0: Picture4.DrawWidth = 3
- Picture4.Line (i, -(x / 100))-(i, (x / 100)), 0
- Picture4.DrawStyle = 2: Picture4.DrawWidth = 1
- Picture4.Line (i, -1)-(i, x + 2), 0
- Picture4.CurrentY = -0.1: Picture4.CurrentX = i: Picture4.Print i
- Next i
- For i = 1 To x + 2
- Picture4.DrawStyle = 0: Picture4.DrawWidth = 3
- Picture4.Line (-(iteraz / 100), i)-((iteraz / 100), i), 0
- Picture4.DrawStyle = 2: Picture4.DrawWidth = 1
- Picture4.Line (-1, i)-(iteraz + 2, i), 0
- Picture4.CurrentX = -0.5: Picture4.CurrentY = i: Picture4.Print i
- Next i
- Picture4.DrawStyle = 0: Picture4.DrawWidth = 3
- For i = 1 To iteraz
- x0 = x: x = fun(x0)
- Picture4.Line (i - 1, x0)-(i, x), vbRed
- Picture4.Circle (i, x), 0.1, vbBlue
- Picture4.Print Round(x, 3)
- Next i
- s = s & "Вычисленное значение корня:" & x1 & vbCrLf
- s = s & "Число итераций:" & iteraz
- Picture3.Print s
- End Sub
- Private Function fun(x As Double) As Double
- fun = Log(x) + 1.8
- End Function
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д