Страница: 1 |
Страница: 1 |
Вопрос: Ребята, помогите чем можете, плиз!!!
Добавлено: 22.05.05 00:33
Автор вопроса: Вероника | ICQ: 233401530
Привет всем!! Помогите решить задачи по VBA..Я вообще не шарю:
1. Найти НОК и НОД чисел a и b
2.Вычислить производную функции в точке a, а также интеграл ее на отрезке [a;b]
3.Перевести произвольное число из десятичнй системы в двоичную
4.Вычислить определитель квадратной матрицы размерности 5*5
5.Решить систему линейных уравнений порядка 5 методом Гаусса.
Числа никакие не даны, наверное брать числа и уравнения произвольно, в общем не знаю
Если не решу, препод на зачете меня убьет!!!
Ответы
Всего ответов: 3
Номер ответа: 1
Автор ответа:
Morpheus
Вопросов: 224
Ответов: 3777
Web-сайт:
Профиль | | #1
Добавлено: 22.05.05 01:19
№1 (Можно немного упростить)
Function NOD(Number1 As Long, Number2 As Long) As Long
If Number1 = Number2 Then
NOD = Number1
Else
If Number1 Mod Number2 = 0 Then
NOD = Number2
Else
If Number2 Mod Number1 = 0 Then
NOD = Number1
Else
s(1) = Number2
s(2) = Number1 Mod Number2
i = 2
 o
i = i + 1
s(i) = s(i - 2) Mod s(i - 1)
Loop Until s(i) = 0
NOD = s(i - 1)
End If
End If
End If
End Function
NOK = (Number1 * Number2) / NOD
Номер ответа: 2
Автор ответа:
Sharp
Лидер форума
ICQ: 216865379
Вопросов: 106
Ответов: 9979
Web-сайт:
Профиль | | #2
Добавлено: 22.05.05 07:04
Нате:
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4065
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4065
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command5
Caption = "Gauss"
Height = 375
Left = 2760
TabIndex = 11
Top = 2040
Width = 1215
End
Begin VB.TextBox Text7
Height = 285
Left = 120
TabIndex = 10
Text = "2,1,2,3,4,5,6"
Top = 2040
Width = 2535
End
Begin VB.CommandButton Command4
Caption = "det"
Height = 375
Left = 2760
TabIndex = 9
Top = 1560
Width = 1215
End
Begin VB.TextBox Text6
Height = 285
Left = 120
TabIndex = 8
Text = "3,1,2,3,2,3,5,1,3,7"
Top = 1560
Width = 2535
End
Begin VB.CommandButton Command3
Caption = "2bin"
Height = 375
Left = 2760
TabIndex = 7
Top = 1080
Width = 1215
End
Begin VB.TextBox Text5
Height = 285
Left = 120
TabIndex = 6
Text = "1231324"
Top = 1080
Width = 2535
End
Begin VB.CommandButton Command2
Caption = "dx и int"
Height = 375
Left = 2760
TabIndex = 5
Top = 600
Width = 1215
End
Begin VB.TextBox Text4
Height = 285
Left = 1440
TabIndex = 4
Text = "4"
Top = 600
Width = 1215
End
Begin VB.TextBox Text3
Height = 285
Left = 120
TabIndex = 3
Text = "3"
Top = 600
Width = 1215
End
Begin VB.TextBox Text2
Height = 285
Left = 1440
TabIndex = 2
Text = "10"
Top = 120
Width = 1215
End
Begin VB.TextBox Text1
Height = 285
Left = 120
TabIndex = 1
Text = "15"
Top = 120
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "НОД"
Height = 375
Left = 2760
TabIndex = 0
Top = 120
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
MsgBox CStr(NOD(Val(Text1), Val(Text2)))
End Sub
Private Function NOD(n1 As Long, n2 As Long) As Long
Do While n2 > 0
n1 = n1 Mod n2
Swap n1, n2
Loop
NOD = n1
End Function
Private Sub Command2_Click()
MsgBox "Производная = " & CStr(dfx(Val(Text3))) & vbCrLf & "Интеграл = " & CStr(intfxdx(Val(Text3), Val(Text4)))
End Sub
Private Function f(x As Double) As Double
f = Sin(x)
End Function
Private Function dfx(a As Double) As Double
eps = 0.0001
dfx = (f(a + eps) - f(a - eps)) / 2 / eps
End Function
Private Function intfxdx(a As Double, b As Double) As Double
Dim c As Double
eps = 0.0001
For c = a To b Step eps
intfxdx = intfxdx + f(c) * eps
Next
End Function
Private Sub Command3_Click()
MsgBox Dec2Bin(Val(Text5))
End Sub
Private Function Dec2Bin(n As Long) As String
i = Int(Log(n) / Log(2))
Do Until n = 0 And i = -1
If n >= 2 ^ i Then
 ec2Bin = Dec2Bin & "1"
n = n - 2 ^ i
Else
 ec2Bin = Dec2Bin & "0"
End If
i = i - 1
Loop
End Function
Private Sub Command4_Click()
Dim a() As Long, n As Long
n = Val(Split(Text6, ","(0))
ReDim a(n, n)
For i = 0 To n - 1
For j = 0 To n - 1
a(j, i) = Val(Split(Text6, ","(i * n + j + 1))
Next
Next
MsgBox Determinant(a(), n)
End Sub
Private Function Determinant(a() As Long, n As Long) As Long
If n = 1 Then
 eterminant = a(0, 0)
Else
Dim m() As Long
ReDim m(n - 1, n - 1)
 eterminant = 0
For i = 0 To n - 1
For j = 0 To n - 2
For k = 0 To n - 2
m(j, k) = a(IIf(j >= i, j + 1, j), k + 1)
Next
Next
 eterminant = Determinant + IIf(i Mod 2 = 0, 1, -1) * a(i, 0) * Determinant(m(), n - 1)
Next
End If
End Function
Private Sub Command5_Click()
Dim a() As Double, b() As Double, n As Long
n = Val(Split(Text7, ","(0))
ReDim a(n, n)
ReDim b(n)
For i = 0 To n - 1
For j = 0 To n - 1
a(j, i) = Val(Split(Text7, ","(i * n + j + 1))
Next
Next
For i = 0 To n - 1
b(i) = Val(Split(Text7, ","(n * n + i + 1))
Next
Dim r() As Double
r = Gauss(a(), b(), n)
For i = 0 To n - 1
res = res & r(i) & " "
Next
MsgBox res
End Sub
Private Function Gauss(a() As Double, b() As Double, n As Long) As Double()
Dim res() As Double
ReDim res(n - 1)
For i = 0 To n - 2
Max = i
For j = i + 1 To n - 1
If Abs(a(i, j)) > Abs(a(i, Max)) Then Max = j
Next
For j = 0 To n - 1
Swap a(j, Max), a(j, i)
Next
Swap b(Max), b(i)
For j = i + 1 To n - 1
q = a(i, j) / a(i, i)
For k = 0 To n - 1
a(k, j) = a(k, j) - a(k, i) * q
Next
b(j) = b(j) - b(i) * q
Next
Next
For i = n - 1 To 0 Step -1
For j = i + 1 To n - 1
b(i) = b(i) - a(j, i) * b(j)
Next
b(i) = b(i) / a(i, i)
Next
Gauss = b
End Function
Private Sub Swap(a, b)
t = a
a = b
b = t
End Sub
Номер ответа: 3
Автор ответа:
Вероника
ICQ: 233401530
Вопросов: 1
Ответов: 1
Профиль | | #3
Добавлено: 22.05.05 10:22
спасибо! Если у кого есть еще какие-либо предложения по теме, пишите...