Несколько курсовых работ (Модуль)

Посмотреть архив целиком

Module Module1

Public n, n1, m, itmax, iter, n2, qq, q, ll, fl, K1, stp As Integer

Public Rung, A(,), A1(,), B1(,), A2(,), Sa(,) As Single

Public B(), B2(,), E1(,), E2(,), C(), eps, aa(), bb(), cc(), dd() As Double

Public sysload As Boolean


Public Sub loadsystemfromfile(ByVal filename As String, ByVal tableName As System.Windows.Forms.DataGridView)

Dim myreader As Microsoft.VisualBasic.FileIO.TextFieldParser

Dim st() As String

myreader = New Microsoft.VisualBasic.FileIO.TextFieldParser(filename)

myreader.SetDelimiters(" ")

ReDim st(1)

st = myreader.ReadFields()

Try

n1 = CInt(st(0)) - 1

Catch

MsgBox("Невозможно прочитать файл", MsgBoxStyle.Critical, " Ошибка файла")

Return

End Try

fl = fl + 1

ReDim A(n1, 1)

tableName.RowCount = n1 + 1 : tableName.ColumnCount = 2

ReDim st(n1 + 1)

For i = 0 To n1

st = myreader.ReadFields()

For j = 0 To 1

A(i, 0) = CSng(st(0))

A(i, 1) = CSng(st(1))

tableName.Item(j, i).Value = st(j)

Next j

Next i

If myreader.ReadToEnd = "" Then

MsgBox("Файл успешно загружен", MsgBoxStyle.OkOnly)

Else

MsgBox("Файл поврежден", MsgBoxStyle.OkOnly)

End If

End Sub

Public Sub interpol()

Dim graph As Graphics = Form1.PictureBox1.CreateGraphics

Form1.PictureBox1.Refresh()

Dim pn As Pen = New Pen(Color.Black, 1)

Dim pn1 As Pen = New Pen(Color.Black, 2)

Dim i, i1, j As Integer

Dim k(m), l(m), h(m), s(m), r(m), ed(,), ost, hh As Double

Dim mh, mw, msY, msX, fi, ms, x As Decimal

ReDim aa(m), bb(m), cc(m + 1), dd(m), ed(n, 2), Sa(n, 2)

k(1) = 0

l(1) = 0

For i = 2 To m

h(i) = B1(i, 1) - B1(i - 1, 1)

h(i - 1) = B1(i - 1, 1) - B1(i - 2, 1)

s(i) = 2 * (h(i) + h(i - 1))

r(i) = 3 * ((B1(i, 2) - B1(i - 1, 2)) / (h(i)) - ((B1(i - 1, 2) - B1(i - 2, 2)) / h(i - 1)))

k(i) = (r(i) - h(i - 1) * k(i - 1)) / (s(i) - h(i - 1) * l(i - 1))

l(i) = h(i) / (s(i) - h(i - 1) * l(i - 1))

Next i

cc(1) = 0

cc(m) = k(m)

For i = (m - 1) To 2 Step (-1)

cc(i) = k(i) - l(i) * cc(i + 1)

Next i

For i = 1 To m

dd(i) = (cc(i + 1) - cc(i)) / (3 * h(i))

bb(i) = (B1(i, 2) - B1(i - 1, 2)) / (h(i)) - ((cc(i + 1) + 2 * cc(i)) * h(i) / 3)

aa(i) = B1(i - 1, 2)

Next i

mh = CSng(Form1.PictureBox1.Height) / 2

mw = CSng(Form1.PictureBox1.Width) / 2

ms = CSng(Form1.TextBox1.Text)

msX = mw / (B1(m, 1) * ms)

msY = mh / (B1(m, 1) * ms / 55)

graph.TranslateTransform(0, mh)

graph.DrawLine(pn1, 0, -mh * 2, 0, mh * 2)

graph.DrawLine(pn1, mw * 2, 0, -mw * 2, 0)

graph.DrawEllipse(Pens.Red, msX * B1(1, 1) - 2, -msY * B1(1, 2) - 2, 4, 4)

graph.DrawEllipse(Pens.Red, msX * B1(m, 1) - 2, -msY * B1(m, 2) - 2, 4, 4)

i1 = 0

For i = 1 To m - 1

hh = 0.1

For x = B1(i, 1) To B1(i + 1, 1) Step hh

fi = aa(i + 1) + bb(i + 1) * (x - B1(i, 1)) + cc(i + 1) * (x - B1(i, 1)) * (x - B1(i, 1)) + dd(i + 1) * (x - B1(i, 1)) * (x - B1(i, 1)) * (x - B1(i, 1))

If x < 1001 Then

ost = (x Mod 50)

If ost = 0 Then

i1 = i1 + 1

ed(i1, 1) = x

ed(i1, 2) = fi

End If

Else

ost = (x Mod 20)

If ost = 0 Then

i1 = i1 + 1

ed(i1, 1) = x

ed(i1, 2) = fi

End If

End If

graph.DrawRectangle(pn, msX * x, -msY * fi, 1, 1)

Next x

Next i

i = 50 : j = 0

Do

If i < 1000 Then

i = i + 50 : j = j + 1

Sa(j, 1) = i

Sa(j, 2) = A1(j, 2) - ed(j, 2)

Else

i = i + 20 : j = j + 1

Sa(j, 1) = i

Sa(j, 2) = A1(j, 2) - ed(j, 2)

End If

Loop Until i = B1(m, 1)

End Sub


Public Sub approks(ByVal mm)

Dim i, j As Integer

ReDim B(mm), B2(mm, mm)

For ii = 0 To mm

For j = 0 To mm

For i = 0 To n - 1

B2(ii, j) = B2(ii, j) + (Sa(i + 1, 1) ^ (j)) * (Sa(i + 1, 1) ^ (ii))

Next i

Next j

Next ii

For i = 0 To mm

For j = 0 To n - 1

B(i) = B(i) + (Sa(j + 1, 2) * Sa(j + 1, 1) ^ (i))

Next j

Next i

End Sub


Public Sub Zeidel(ByVal itmax, ByRef it, ByVal mm)

Dim S, T, Mn, x3() As Double

Dim i, j, fl As Integer

ReDim C(mm), x3(mm) 'задание начального приближения

it = 0

fl = 1

Do

it = it + 1

If it > 1 Then

fl = 0

For i = 0 To mm

Mn = 0

Mn = C(i) - x3(i)

If Math.Abs(Mn) > eps Then

fl = 1

End If

Next

For i = 0 To mm

x3(i) = C(i)

Next

End If

i = 0

Do

S = 0

For j = 0 To mm

If i <> j Then

S = S + B2(i, j) * C(j)

End If

Next

T = B(i) - S

C(i) = T / B2(i, i)

i = i + 1

Loop While i <= mm

Loop While (fl = 1) And (it < itmax)

End Sub

Public Function fynk(ByVal X, ByVal k)

Dim i As Integer

For i = 0 To k

fynk = fynk + C(i) * X ^ i

Next

End Function

Public Function hord(ByVal x1, ByVal x12)

Dim eps1 As Single

eps1 = CSng(Form1.TextBox5.Text)

iter = 0

Do

iter = iter + 1

x1 = x1 + (x12 - x1) * (fynk(x1, stp)) / (fynk(x1, stp) - fynk(x12, stp))

Loop While (Math.Abs(fynk(x1, stp)) >= eps1)

hord = x1

End Function

Public Function pr(ByVal xx1, ByVal xx2, ByVal h)

Dim sum, x As Double

sum = 0 : q = 0

For x = xx1 To xx2 Step h

sum = sum + h * fynk(x, stp)

Next

pr = sum + osh(xx1, xx2, h)

q = 1

End Function

Public Function trap(ByVal xx1, ByVal xx2, ByVal h)

Dim sum, x3 As Single

sum = 0 : q = 0

For x3 = xx1 + h To xx2 - h Step h

sum = sum + fynk(x3, stp)

Next

sum = 2 * sum + fynk(xx1, stp) + fynk(xx2, stp)

trap = (h / 2) * sum

trap = trap + oshib(xx1, xx2, h)

q = 2

End Function

Public Function osh(ByVal xx1, ByVal xx2, ByVal h)

Dim sum, x As Double

sum = 0

For x = xx1 To xx2 Step h

sum = sum + h * fp1(x)

Next

osh = (h / 2) * sum

End Function

Public Function oshib(ByVal xx1, ByVal xx2, ByVal h)

Dim sum, x3 As Double

sum = 0

For x3 = xx1 To xx2 Step h

sum = sum + h * fp2(x3)

Next

oshib = -((h ^ 2) / 12) * sum

End Function

Public Sub runge(ByVal xx1, ByVal xx2, ByVal h)

Dim kof As Single

kof = CInt(Form1.TextBox7.Text)

Rung = 0

If q = 1 Then

Rung = (pr(xx1, xx2, h) - pr(xx1, xx2, h * kof)) / (kof ^ 2 - 1)

Else

Rung = (trap(xx1, xx2, h) - trap(xx1, xx2, h * kof)) / (kof ^ 2 - 1)

End If

End Sub

Function fp2(ByVal X) 'производная второй степени аппроксимирующей функции

For i = 2 To stp

fp2 = fp2 + C(i) * i * (i - 1) * X ^ (i - 2)

Next

End Function

Function fp1(ByVal X)

For i = 1 To stp

fp1 = fp1 + C(i) * X ^ (i - 1) * i

Next

End Function


End Module


Случайные файлы

Файл
29266.rtf
141451.rtf
144380.rtf
176205.rtf
83697.rtf




Чтобы не видеть здесь видео-рекламу достаточно стать зарегистрированным пользователем.
Чтобы не видеть никакую рекламу на сайте, нужно стать VIP-пользователем.
Это можно сделать совершенно бесплатно. Читайте подробности тут.