XL 2010 Produit matriciel avec une matrice inverse

Alex98

XLDnaute Nouveau
Bonjour, j'aimerais faire le produit matriciel entre l'inverse d'une matrice et une matrice colonne. J'ai pour erreur "l'indice n'appartient pas à la séléction" pour
MatriceX2(i - 1, 0) = P(i - 1, 0) * X(i - 1, 0) + _
P(i - 1, 1) * X(i - 1, 0) + _
P(i - 1, 2) * X(i - 1, 0)
Pouvez-vous m'aider s'il vous plait ?



Function Pinv(Angle As Double) As Variant
Dim Matinverse() As Variant

'Calcule de la matrice iverse

Matinverse = Application.MInverse(Range("B27:D29"))
Pinv = Matinverse


End Function


Function Mat_X(Angle As Double) As Variant
Dim MatIntX(3, 1) As Double

'Détermination de la matrice X

MatIntX(0, 0) = Cells(5, 8)
MatIntX(1, 0) = Cells(6, 8)
MatIntX(2, 0) = Cells(7, 8)

Mat_X = MatIntX

End Function


Function Mat_ProdPX(Angle As Double) As Variant
'M1M2 = P
'X2 = X'

'Initialisation
Dim MatriceX2(3, 1) As Double
Dim P As Variant
Dim X As Variant
Dim i, j As Integer


'Calcule de X'=Pinv*X

P = Pinv(Angle)
X = Mat_X(Angle)


For i = 1 To 3

MatriceX2(i - 1, 0) = P(i - 1, 0) * X(i - 1, 0) + _
P(i - 1, 1) * X(i - 1, 0) + _
P(i - 1, 2) * X(i - 1, 0)


Cells(13 + i, 8) = MatriceX2(i - 1, 0)

Next i



End Function
 

sylvanu

XLDnaute Barbatruc
Supporter XLD
Bonjour Alex,
Votre indice min de P est 1 et non 0.
Donc quand il y a P((i-1,0) avec i=1 il y a erreur.
En faisant :
VB:
MatriceX2(i - 1, 0) = P(i, 1) * X(i - 1, 0) + _
                      P(i, 2) * X(i - 1, 0) + _
                      P(i, 3) * X(i - 1, 0)
Il n'y a plus d'erreur.
Ce qu'on voit bien sur un point d'arrêt :
1655721934237.png
 

Alex98

XLDnaute Nouveau
Comment peut-on afficher la matrice inverse ? J'ai encore une erreur d'indice
J'ai besoin de l'afficher car le produit matriciel entre l'inverse de P et X n'est pas bon

Function Pinv(Angle As Double) As Variant
Dim Matinverse() As Variant

'Calcule de la matrice iverse

Matinverse = Application.MInverse(Range("B27:D29"))

For i = 1 To 3
For j = 1 To 3

Cells(56 + i, 1 + j) = Matinverse(i - 1, j - 1)

Next j
Next i


Pinv = Matinverse


End Function
 

Alex98

XLDnaute Nouveau
VB:
   Function Pinv(Angle As Double) As Variant
        Dim Matinverse() As Variant
        
        'Calcul de la matrice inverse
        
        Matinverse = Application.MInverse(Range("B27:D29"))
        
        For i = 1 To 3
            For j = 1 To 3
                                        
                 Cells(46 + i, 1 + j) = Matinverse(i - 1, j - 1)
                
            Next j
        Next i
        
        
        Pinv = Matinverse
    
    
    End Function

    
    Function Mat_X(Angle As Double) As Variant
        Dim MatIntX(3, 1) As Double
        
        'Détermination de la matrice X
        
        MatIntX(0, 0) = Cells(5, 8)
        MatIntX(1, 0) = Cells(6, 8)
        MatIntX(2, 0) = Cells(7, 8)
        
        Mat_X = MatIntX
    
    End Function
    
    
    Function Mat_ProdPX(Angle As Double) As Variant
    'M1M2 = P
    'X2 = X'
    
    'Initialisation
        Dim MatriceX2(3, 1) As Double
        Dim P As Variant
        Dim X As Variant
        Dim i, j As Integer
      
        
     'Calcule de X'=Pinv*X
    
        P = Pinv(Angle)
        X = Mat_X(Angle)
      
        
        For i = 1 To 3
        
                MatriceX2(i - 1, 0) = P(i, 1) * X(i - 1, 0) + _
                      P(i, 2) * X(i - 1, 0) + _
                      P(i, 3) * X(i - 1, 0)
            
                    
                Cells(13 + i, 8) = MatriceX2(i - 1, 0)
                
        Next i

    

    End Function

Comme cela ?
 

Pièces jointes

  • fichiertest.xlsx
    13.9 KB · Affichages: 2

Alex98

XLDnaute Nouveau
J'ai réussi à l'afficher mais je ne comprends pas pourquoi mon produit matriciel entre Pinv et Mat_X
VB:
MatriceX2(i - 1, 0) = P(i, 1) * X(i - 1, 0) + _
                      P(i, 2) * X(i - 1, 0) + _
                      P(i, 3) * X(i - 1, 0)
Le problème vient surement d'ici mais je ne vois pas comment
 

Statistiques des forums

Discussions
311 725
Messages
2 081 947
Membres
101 849
dernier inscrit
florentMIG