Sub Sistema_lineare()
Dim i, j, k, D1, r, c, d, l, m, n, h As Integer
Dim B(), B1(), v(), x() As Object
1:
r = InputBox("Digita numero di righe.")
If Not IsNumeric(r) Then
MsgBox "Devi immettere un valore numerico!"
GoTo 1
End If
2:
c = InputBox("Digita numero di colonne.")
If Not IsNumeric(c) Then
MsgBox "Devi immettere un valore numerico!"
GoTo 2
End If
If r <> c Then
MsgBox "Se n°righe non = n°colonne non posso continuare."
Exit Sub
End If
For i = 1 To c
For j = 1 To r
Cells(i, j) = InputBox("Inserisci l'elemento " & i & "," & j & " Della matrice dei coefficienti.")
If Not IsNumeric(Cells(i, j)) Then
MsgBox "Devi immettere valori numerici! All' n'facc'!!"
Exit Sub
End If
Next j
Next i
B = Range(Cells(1, 1), Cells(i - 1, j - 1))
Range(Cells(1, 1), Cells(i - 1, j - 1)).Select
B1 = Application.WorksheetFunction.MInverse(B)
For l = 1 To c
For m = 1 To r
Range(Cells(1 + i, 1), Cells(i + i - 1, j - 1)).Value = B1
Next m
Next l
3:
d = InputBox("Digita numero di termini noti.")
If Not IsNumeric(d) Then
MsgBox "Devi immettere un valore numerico!"
GoTo 3
End If
For k = 1 To d
Cells(k, j + 1) = InputBox("Inserisci l'elemento " & k & ", della matrice dei coefficienti.")
If Not IsNumeric(Cells(k, j + 1)) Then
MsgBox "Devi immettere valori numerici! All' n'facc'!!"
Exit Sub
End If
Next k
v = Range(Cells(1, c + 2), Cells(r, c + 2))
x = Application.WorksheetFunction.MMult(Range(Cells(r + 2, 1), Cells(r + r + 1, c)), Range(Cells(1, c + 2), Cells(r, c + 2)))
For n = 1 To d
Cells(n + r + 1, c + 2).Value = Application.WorksheetFunction.MMult(Range(Cells(n + 2, 1), Cells(n + n + 1, c)), Range(Cells(n, c + 2), Cells(n, c + 2)))
Next n
'For n = 1 To d
'h = 1
'Cells(n + r + 1, c + 2) = Cells(n + r + h, n) * Cells(h, c + 2) + Cells(n + r + 1, n + 1) * Cells(h + 1, c + 2)
'Cells(n + r + 1, c + 1 + 1) = Cells(n + r + 1, h) * Cells(n, c + 2) + Cells(n + r + n, h + 1) * Cells(n + 1, c + 2) 'prima era:+ Cells(n + r + 1, n + 1)
'Da eliminare: Cells(n + r + 1, c + 1 + 1) = (2 * Cells(n, c + 2)) + (2 * Cells(n, c + 2 + n))
'Cells(n + r + 1, c + 1 + 1) = Cells(n + r + 1, h) * Cells(n, c + 2) + Cells(n + r + 1, h + 1) * Cells(n + h, c + 2)
'h = h + 1
'Next n
'h = h + 1
End Sub
|