Problema assegnazione variabili VB

giovedì 20 novembre 2008 - 15.49

dando Profilo | Newbie

Ciao a tutti. Ho trovato questo codice per la gestione delle matrici in VB (in realtà è molto piu complesso ma ne riporto solo una parte)


'------------------------------------------------------------------------------
Public Structure Matrice


Private Coeff(,) As Long
Private mDim1 As Long, mDim2 As Long



Sub New(ByVal dim1 As Long, ByVal dim2 As Long)
Dim longA(dim1, dim2) As Long
Coeff = longA
mDim1 = dim1
mDim2 = dim2
End Sub


Default Public Property Item(ByVal dim1 As Long, ByVal dim2 As Long) As Long ' TYPE
Get
If dim1 <= mDim1 And dim2 <= mDim2 And dim1 >= 0 And dim2 >= 0 Then
Return Coeff(dim1, dim2)
End If
End Get
Set(ByVal value As Long)
If dim1 <= mDim1 And dim2 <= mDim2 And dim1 >= 0 And dim2 >= 0 Then
Coeff(dim1, dim2) = value
End If
End Set
End Property

Public ReadOnly Property Dim1() As Long
Get
Return mDim1
End Get
End Property
Public ReadOnly Property Dim2() As Long
Get
Return mDim2
End Get
End Property



Function Transpose() As Matrice
'TRANSPOSE MATRICIELLE
Dim result As New Matrice(mDim2, mDim1)

'Transpose
For i As Long = 1 To mDim1
For j As Long = 1 To mDim2
result(i, j) = Coeff(j, i)
Next j, i

Return result
End Function

Public ReadOnly Property Trace() As Long ' TYPE
Get
'TRACE DE LA MATRICE

'Paramètres
Dim tmp As Long

'Vérifications
If mDim1 <> mDim2 Then
Err.Raise(Number:=513, Source:="MATRICE", Description:="MATRICE NON CARRE")
Else
'Addition ou soustraction
For i As Long = 1 To mDim1
tmp += Me(i, i)
Next i
End If
End Get
End Property

Public ReadOnly Property Inverse() As Matrice
Get
'INVERSION MATRICE METHODE DE GAUSS JORDAN

'Paramètres
Dim i As Long, j As Long, k As Double
Dim Dummy As Double
Dim B As New Matrice(mDim1, mDim1)

'Vérifications
If mDim1 <> mDim2 Then
'Err.Raise(Number:=513, Source:="MATRICE", Description:="MATRICE NON CARRE")
Return B
Else
'Algo

For k = 1 To mDim1
B(k, k) = 1
Next k
For k = 1 To mDim1
Dummy = Coeff(k, k)
For j = 1 To mDim1
Coeff(k, j) = Coeff(k, j) / Dummy
B(k, j) = B(k, j) / Dummy
Next j
For i = 1 To mDim1
If i <> k Then
Dummy = Coeff(i, k)
For j = 1 To mDim1
Coeff(i, j) = Coeff(i, j) - Dummy * Coeff(k, j)
B(i, j) = B(i, j) - Dummy * B(k, j)
Next j
End If
Next i
Next k

'renvoi
Return B
End If
End Get
End Property
End Strucure
'------------------------------------------------------------------------------

Ora, se aggegno ad esempio dal form1.load dei valori ad una matrice questi vengono tutti sballati se è presente la funzione INVERSE
(dove per altro in fase di debug non entra mai)


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim asdf As New Matrice2(2, 2)
asdf(0, 0) = 1
asdf(0, 1) = 2
asdf(0, 2) = 3

asdf(1, 0) = 3
asdf(1, 1) = 4
asdf(1, 2) = 5

asdf(2, 0) = 7
asdf(2, 1) = 6
asdf(2, 2) = 5
end sub


se invece lascio virgolettata la funzione INVERSE i valori di asdf.coeff corrispondono a quelli di input.
Qualcuno mi sa dire dov'e l'errore?

Grazie mille
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5