Inverting a Matrix
Inverting a Matrix
(OP)
I'm trying to write a macro that will invert a square matrix of any random size. Say I have a 10 x 10 matrix, how do I word the macro such that it selects from A1:J10 and then inverts that matrix? I already have an ad-in that will allow me to invert larger matrices than Excel normally allows. Thanks!





RE: Inverting a Matrix
thread764-29458
RE: Inverting a Matrix
CODE
Dim Inverted as Variant
MatRows = Uninverted.Rows.Count
MatCols = Ininverted.Columns.Count
' Test that MatRows equals MatCols
... Code to your taste
ReDim Inverted(1 to MatRows, 1 to MatCols)
' Do the inversion
... Algorithm and code to your taste
Matinverter = Inverted
End Function
RE: Inverting a Matrix
Cheers
Greg Locock
Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
RE: Inverting a Matrix
RE: Inverting a Matrix
CODE
Dim Inverted as Variant
MatRows = Uninverted.Rows.Count
MatCols = Ininverted.Columns.Count
' Test that MatRows equals MatCols
... Code to your taste
' Test that Size is within the limits.
... Code to your taste
ReDim Inverted(1 to MatRows, 1 to MatCols)
' Do the inversion by restricting yourself
' to rows 1 to Size and columns 1 to Size.
... Algorithm and code to your taste
' Fill rows Size+1 to MatRows and columns Size+1 to MatCols
' with some sort of null.
... Code to your taste
Matinverter = Inverted
End Function
Alternatively, you may be able to use my original approach provided you can find an inversion algorithm that is not sensitive to large blocks of zeroes.
RE: Inverting a Matrix
RE: Inverting a Matrix
(2) Type the formula, ie "=MatInverter(A1:BL64,A66)" where A66 is the cell containing the used size of the megamatrix.
(3) When you have completed typing the formula, use <Ctrl-Shift-Enter> instead of merely <Enter>. This tells Excel that the formula you have just typed is to be treated as an "array formula".
(4) Now when you place your cursor anywhere inside A71:BL134 the formula will appear inside {braces}. This is Excel's way of telling you that it is an array formula.
All of this is the same as it would be if you were using one of Excel's standard array formulae, such as MINVERSE.
RE: Inverting a Matrix
Transfer your data into matrix A and perform Gaussian elimination of lower triangular and upper triangular matrix on A and B as they were a single n*2n matrix.
At the end you will get an inverse in matrix B.
m777182
RE: Inverting a Matrix
__________________________________________________________
first = -8
Range("A9:D12").Select
Selection.FormulaArray = "=MINVERSE(R[first]C:R[-5]C[3])"
__________________________________________________________
What I have doesn't work. I want to make the number in the brackets a variable. Can you do this? My guess is no but you obviously have more experience than I do.
RE: Inverting a Matrix