Storing values from row operations

birdec

New Member
Joined
Jul 7, 2011
Messages
19
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!

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:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
how about just storing the last used value somewhere on the sheet whilst its working
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top