Реализация приближенного метода решения уравнения - Visual Basic .NET
Формулировка задачи:
Риализация приближенного метода решения уравнения средствами VB. (првоести отделение корней графически на форме, и уточнить корни методом половинного деления X^6-2x^5+3x-8=0)
Решение задачи: «Реализация приближенного метода решения уравнения»
textual
Листинг программы
Public Class Form3
Private ww, hh As Integer
Private xy() As PointF
Private isLoad As Boolean
Private pn0, pn2 As Pen
Private Sub Form3_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
With PictureBox1
ww = .Width / 2
hh = .Height / 2
.BorderStyle = BorderStyle.FixedSingle
.BackColor = Color.White
End With
pn0 = New Pen(Brushes.Black, 1)
pn2 = New Pen(Brushes.Red, 1)
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
isLoad = True
Dim ff = Function(x) x ^ 6 - 2 * x ^ 5 + 3 * x - 8
Dim stp As Double = 0.2
ReDim xy(4 / stp)
Dim i As Integer
For xx = -2 To 2 Step stp
xy(i) = New PointF(xx, ff(xx))
i += 1
Next
PictureBox1.Invalidate()
End Sub
Private Sub PictureBox1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
If Not isLoad Then Exit Sub
Dim k As Integer = 20
Dim g As Graphics = e.Graphics
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
g.TranslateTransform(ww, hh)
g.ScaleTransform(1, -1)
'оси координат
g.DrawLine(pn0, New Point(0, hh), New Point(0, -hh))
g.DrawLine(pn0, New Point(-ww, 0), New Point(ww, 0))
'отметки на осях
Dim ax() As Point = {New Point(-2, 0), New Point(-1, 0), New Point(1, 0), New Point(2, 0)}
Dim ay(19) As Point
Dim t As Integer = 1
For i = 0 To ay.Length / 2 - 1
ay(i) = New Point(0, -t)
ay(i + ay.Length / 2) = New Point(0, t)
t += 1
Next
'масштабирование
Dim mm As New Drawing2D.Matrix
mm.Scale(k, k, Drawing2D.MatrixOrder.Append)
mm.TransformPoints(xy)
mm.TransformPoints(ax)
mm.TransformPoints(ay)
'отметки на осях
Dim ss As Integer = 5
For i = 0 To ax.Length - 1
g.DrawLine(pn0, ax(i), New Point(ax(i).X, ax(i).Y + ss))
Next
For i = 0 To ay.Length - 1
g.DrawLine(pn0, ay(i), New Point(ay(i).X + ss, ay(i).Y))
Next
'кривая
g.DrawLines(pn2, xy)
End Sub
End Class