Технический форум

Технический форум (http://www.tehnari.ru/)
-   Помощь студентам (http://www.tehnari.ru/f41/)
-   -   Visual Basic 2008 программирование очень нужна помощь (http://www.tehnari.ru/f41/t42395/)

Alex0161 22.11.2010 08:33

Visual Basic 2008 программирование очень нужна помощь
 
построить таблицу и найти наименьшие значение функции y=f(x) при изменении на отрезке [a,b} c шагом h
Y=x+1/x. Отрезок [0.1,2.5], шаг h=0.1
у меня программа не строит график помогите найти ошибку
код программы:

Public Class Class1
Public a1, b1, h1
Public ReadOnly Property a() As Single
Get
Return a1
End Get
End Property
Public ReadOnly Property b() As Single
Get
Return b1
End Get
End Property
Public ReadOnly Property h() As Single
Get
Return h1
End Get
End Property
Public Sub inputF()
a1 = CSng(InputBox("введите начальное значение функции"))
b1 = CSng(InputBox("введите конечное значение функции"))
h1 = CSng(InputBox("введите шаг"))
End Sub

End Class

Public Class Form1
Dim put As Class1 = New Class1
Public dx, dy, a, b, h As Single
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x, y, xmax, ymax, xmin, ymin, dx, dy, xm, xn As Single
Dim n As Integer
ymax = -1.0E+38 : ymin = 1.0E+38
xmax = -1.0E+38 : xmin = 1.0E+38
put.inputF()
a = put.a
b = put.b
h = put.h
TextBox2.Text = Str(a)
TextBox3.Text = Str(b)
TextBox4.Text = Str(h)
n = (b - a) / h ^ 2

x = a
For i As Integer = 1 To n
x += h
y = x + 1 / x
ListBox1.Items.Add(x)
ListBox2.Items.Add(y)
ListBox3.Items.Add(i)
If x < xmin Then
xmin = x
End If
If x > xmax Then
xmax = x
End If
If y < ymin Then
ymin = y : xm = x
End If
If y > ymax Then
ymax = y : xn = x
End If
Next
dx = Math.Abs(xmax - xmin)
dy = Math.Abs(ymax - ymin)
TextBox1.Text = "Наименьшее значение функции " & Str(ymin) & " при x= " & Str(xm) & vbCrLf & vbCrLf
TextBox1.Text = TextBox1.Text & "Наименьшее значение функции " & Str(ymin) & " при x= " & Str(xn) & vbCrLf
End Sub



Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Hide()
Form2.Show()
End Sub
End Class

Imports System.Math
Public Class Form2
Private Sub form2_paint(ByVal sender As Object, ByVal el As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim GF As System.Drawing.Graphics
GF = Label1.CreateGraphics
Dim GF2 As System.Drawing.Graphics
GF2 = Label2.CreateGraphics
Dim PenColor As New System.Drawing.Pen(System.Drawing.Color.Red)
GF.DrawLine(PenColor, 50, 0, 50, Label1.Height)
GF.DrawString("x", Label1.Font, Brushes.DarkRed, Label1.Width - 15, Label1.Height - 25)
GF.DrawLine(PenColor, 0, Label1.Height - 25, Label1.Width, Label1.Height - 25)
GF.DrawString("y", Label1.Font, Brushes.DarkRed, Label1.Width \ 2 - 100, 1)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim a, b, h, n, x, y, xmax, xmin, ymin, ymax, dx, dy As Single
Dim k As Integer, p As String
Dim GF As System.Drawing.Graphics
GF = Label1.CreateGraphics
Dim GF2 As System.Drawing.Graphics
GF2 = Label2.CreateGraphics
Dim PenColor As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim x1, y1, x2, y2, x3, y3, x4, y4, xa, ya As Single
a = Form1.a
b = Form1.b
h = Form1.h
n = (b - a) / h
ymax = -1.0E+38 : ymin = 1.0E+38
xmax = -1.0E+38 : xmin = 1.0E+38
x = a
For i As Integer = 1 To n
x += h
If x < xmin Then
xmin = x
End If
If x > xmax Then
xmax = x
End If
If y < ymin Then
ymin = y
End If
If y > ymax Then
ymax = y
End If
Next
dx = Abs(xmax - xmin)
dy = Abs(ymax - ymin)
x = a : k = 0
For i As Integer = 1 To n
x += h
y = x + 1 / x
xa = x * Label1.Width \ dx + 50 : ya = Label1.Height - y * Label1.Height \ dy - 50
GF.FillEllipse(Brushes.Red, xa, ya, 3, 7)
p = Mid(Str(x), 1, 4)
If i Mod 25 = 0 Then
GF.DrawString(p, Label1.Font, Brushes.DarkRed, xa - 30, Label1.Height - 20)
End If

If i Mod (n \ 5) = 0 And i > 32 Then
k += 1
Select Case k
Case 1
x1 = xa : y1 = ya
Case 2
x2 = xa : y2 = ya
Case 3
x3 = xa : y3 = ya
Case 4
x4 = xa : y4 = ya
End Select
End If
Next

y = ymax + 10 : h = dy / 5
For s As Single = 2 To Label1.Height Step 16
y -= h
p = Mid(Str(y), 1, 5)
GF.DrawString(p, Label1.Font, Brushes.DarkRed, 5, s)
Next

Dim points() As Point = {New Point(x1, y1), New Point(x2, y2), New Point(x3, y3), New Point(x4, y4)}
For t As Single = 0 To 2.5 Step 0.5
GF2.DrawCurve(Pens.Blue, points, t)
Next
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form1.Show()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
End
End Sub
End Class

Alex0161 23.11.2010 11:44

очень прошу помогоите


Часовой пояс GMT +4, время: 04:27.

Powered by vBulletin® Version 4.5.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.