I built a function that takes a matrix, performs simple linear algebra, and outputs a new matrix with 0's in the bottom left corner.
This is great but I need the code to remember the value it multiplied by ("the factor") to get each 0 in the bottom left corner and output each factor later maybe using another function.
For example,
For Column 1, (row, column):
The 1st factor = A(2,1)/A(1,1) and would eventually be output in a new matrix in position (2,1)
The 2nd factor (if any) = A(3,1)/A(1,1) and would eventually be output in a new matrix in position (3,1)
The 3rd factor (if any) = A(4,1)/A(1,1) etc, etc
For Column 2:
The 1st factor = A(3,2)/A(2,2) and would eventually be output in a new matrix in position (3,2)
The 2nd factor = A(4,2)/A(2,2) etc, etc
For n rows and columns
I'm not sure how to code this and how I could retrieve it later. Sorry if this was confusing - would love some feedback. Thanks!
This is great but I need the code to remember the value it multiplied by ("the factor") to get each 0 in the bottom left corner and output each factor later maybe using another function.
For example,
For Column 1, (row, column):
The 1st factor = A(2,1)/A(1,1) and would eventually be output in a new matrix in position (2,1)
The 2nd factor (if any) = A(3,1)/A(1,1) and would eventually be output in a new matrix in position (3,1)
The 3rd factor (if any) = A(4,1)/A(1,1) etc, etc
For Column 2:
The 1st factor = A(3,2)/A(2,2) and would eventually be output in a new matrix in position (3,2)
The 2nd factor = A(4,2)/A(2,2) etc, etc
For n rows and columns
I'm not sure how to code this and how I could retrieve it later. Sorry if this was confusing - would love some feedback. Thanks!
Code:
Function GaussU(AA, BB)
Dim A, B, C
A = AA
M = UBound(A, 1)
N = UBound(A, 2)
B = BB
k = UBound(B)
ReDim C(1 To N, 1 To N + 1)
If M <> N Or k <> N Then
GaussU = "Error"
Else
For i = 1 To N
For j = 1 To N
C(i, j) = A(i, j)
Next j
C(i, N + 1) = B(i, 1)
Next i
For k = 1 To N - 1
For i = k + 1 To N
factor = C(i, k) / C(k, k)
For j = 1 To N + 1
C(i, j) = C(i, j) - (factor * C(k, j))
Next j
Next i
Next k
GaussU = C
End If
End Function
Last edited: