1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| Function calculmatriceEriic2(x As Range)
Dim i As Long 'pour parcourir les lignes de la matrice
Dim j As Long 'pour parcourir les colonnes de la matrice
Dim n As Single 'taille de la matrice
Dim matrice() As Double
rot = Array(2, 2, 2) 'Tableau à une dimension dont le 1er indice est 0, on aura donc 0, 1, 2 => rot(0) -> 2 - rot(1) -> 2 - rot(2) -> 2
'Si l'indice du tableau matrice commence à 1 => i = 1 => on aura alors rot(i-1) pour obtenir la 1è valeur du tableau rot (i-1=0) et ainsi de suite
n = Application.CountA(x) - 1
ReDim matrice(1 To n, 1 To n)
For i = 1 To n
For j = 1 To n
If i = j Then
matrice(i, j) = 2 * (x(i) + x(i + 1))
ElseIf i > j And i - j = 1 Then
matrice(i, j) = x(i)
ElseIf j > i And j - i = 1 Then
matrice(i, j) = x(j)
End If
Next
Next
For j = 1 To UBound(matrice, 2)
matrice(1, j) = rot(j - 1)
Next
calculmatriceEriic2 = matrice 'valeur à changer pour obtenir toute les valeurs de la matrice
End Function |
Partager