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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
how about just storing the last used value somewhere on the sheet whilst its working
 
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,551
Members
449,170
Latest member
Gkiller

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