Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel VBA Matrix Operations
How do I do matrix operations from within an Excel VBA macro?
Specifically matrix multiplication (MULT) and matrix inversion (MINVERT). *** Sent via Developersdex http://www.developersdex.com *** |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel VBA Matrix Operations
Check this out:
http://people.revoledu.com/kardi/tut...LinearEqs.html http://www.techonthenet.com/excel/formulas/mmult.php And this: http://www.bettersolutions.com/excel...O520748331.htm http://faculty.kfupm.edu.sa/SE/salamah/matrix/ HTH, Ryan-- -- Ryan--- If this information was helpful, please indicate this by clicking ''Yes''. "Kirby Holte" wrote: How do I do matrix operations from within an Excel VBA macro? Specifically matrix multiplication (MULT) and matrix inversion (MINVERT). *** Sent via Developersdex http://www.developersdex.com *** |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel VBA Matrix Operations
How do I do matrix operations from within an Excel VBA macro?
Hi. One way... Sub Demo() Dim a, m a = [{3,4; 5,6}] With WorksheetFunction m = .MMult(a, a) m = .MInverse(a) End With End Sub = = = = = = = HTH :) Dana DeLouis Kirby Holte wrote: How do I do matrix operations from within an Excel VBA macro? Specifically matrix multiplication (MULT) and matrix inversion (MINVERT). *** Sent via Developersdex http://www.developersdex.com *** |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel VBA Matrix Operations
Thanks for the help.
Matrix Operations from within VBA The following subroutine is called from another subroutine. Arrays p, vr, vi, Qr, Qi and Pinv were dimensioned Dim p(), etc prior to the subroutines. All arrays are Real. The matrix operation for Pinv() worked fine. The operations for vr and vi arrays also worked fine. However, when calculations got to Qr, I received an error message €œRun Time Error €˜1001€ unable to get MMult property of the worksheetFunction.class. €œnc€ is 8 in the following. Can anyone help? Note, I wrote a very simple VBA routine to multiply a 3X3 times a 3X1 matrix and called the resultant matrix €œC€. C should be of dimensions 3X1. I included a MsgBox(C(1)) and the program hung up. When I changed it to MsgBox(C(1,1)), the program ran. Note, C was dimensioned (as a 1X3) €¦ Dim C(1 To 3) array. Sub Qmatrix() ReDim vr(1 To nc), vi(1 To nc), Qr(1 To nc), Qi(1 To nc), Pinv(1 To nc, 1 To nc) Pinv() = Application.WorksheetFunction.MInverse(p()) For j = 1 To nc vr(j) = v(j) * Cos(va(j) * pi / 180) vi(j) = v(j) * Sin(va(j) * pi / 180) Next j Qr = Application.WorksheetFunction.MMult(Pinv, vr) Qi = Application.WorksheetFunction.MMult(Pinv, vi) End Sub "Dana DeLouis" wrote: How do I do matrix operations from within an Excel VBA macro? Hi. One way... Sub Demo() Dim a, m a = [{3,4; 5,6}] With WorksheetFunction m = .MMult(a, a) m = .MInverse(a) End With End Sub = = = = = = = HTH :) Dana DeLouis Kirby Holte wrote: How do I do matrix operations from within an Excel VBA macro? Specifically matrix multiplication (MULT) and matrix inversion (MINVERT). *** Sent via Developersdex http://www.developersdex.com *** |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel VBA Matrix Operations
ReDim .... Pinv(1 To nc, 1 To nc)
Pinv() = Application.WorksheetFunction.MInverse(p()) Hi. Not sure, but try using a variant as in the example below. Good luck. Are you doing some variation of a Fourier analysis? Sub Qmatrix() Dim P As Variant Dim Good As Variant Dim Bad() ReDim Bad(1 To 2, 1 To 2) P = [{1,2; 3,4}] Bad = WorksheetFunction.MInverse(P()) Good = WorksheetFunction.MInverse(P) End Sub Kirby wrote: Thanks for the help. Matrix Operations from within VBA The following subroutine is called from another subroutine. Arrays p, vr, vi, Qr, Qi and Pinv were dimensioned Dim p(), etc prior to the subroutines. All arrays are Real. The matrix operation for Pinv() worked fine. The operations for vr and vi arrays also worked fine. However, when calculations got to Qr, I received an error message €œRun Time Error €˜1001€ unable to get MMult property of the worksheetFunction.class. €œnc€ is 8 in the following. Can anyone help? Note, I wrote a very simple VBA routine to multiply a 3X3 times a 3X1 matrix and called the resultant matrix €œC€. C should be of dimensions 3X1. I included a MsgBox(C(1)) and the program hung up. When I changed it to MsgBox(C(1,1)), the program ran. Note, C was dimensioned (as a 1X3) €¦ Dim C(1 To 3) array. Sub Qmatrix() ReDim vr(1 To nc), vi(1 To nc), Qr(1 To nc), Qi(1 To nc), Pinv(1 To nc, 1 To nc) Pinv() = Application.WorksheetFunction.MInverse(p()) For j = 1 To nc vr(j) = v(j) * Cos(va(j) * pi / 180) vi(j) = v(j) * Sin(va(j) * pi / 180) Next j Qr = Application.WorksheetFunction.MMult(Pinv, vr) Qi = Application.WorksheetFunction.MMult(Pinv, vi) End Sub "Dana DeLouis" wrote: How do I do matrix operations from within an Excel VBA macro? Hi. One way... Sub Demo() Dim a, m a = [{3,4; 5,6}] With WorksheetFunction m = .MMult(a, a) m = .MInverse(a) End With End Sub = = = = = = = HTH :) Dana DeLouis Kirby Holte wrote: How do I do matrix operations from within an Excel VBA macro? Specifically matrix multiplication (MULT) and matrix inversion (MINVERT). *** Sent via Developersdex http://www.developersdex.com *** |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel VBA Matrix Operations
Thanks Dana,
I will give your suggestion a try on Thursday. Taking a day off tomorrow to work on my boat. The program is to compute various parameters for high voltage electric power transmission lines ... Kirby "Dana DeLouis" wrote: ReDim .... Pinv(1 To nc, 1 To nc) Pinv() = Application.WorksheetFunction.MInverse(p()) Hi. Not sure, but try using a variant as in the example below. Good luck. Are you doing some variation of a Fourier analysis? Sub Qmatrix() Dim P As Variant Dim Good As Variant Dim Bad() ReDim Bad(1 To 2, 1 To 2) P = [{1,2; 3,4}] Bad = WorksheetFunction.MInverse(P()) Good = WorksheetFunction.MInverse(P) End Sub Kirby wrote: Thanks for the help. Matrix Operations from within VBA The following subroutine is called from another subroutine. Arrays p, vr, vi, Qr, Qi and Pinv were dimensioned Dim p(), etc prior to the subroutines. All arrays are Real. The matrix operation for Pinv() worked fine. The operations for vr and vi arrays also worked fine. However, when calculations got to Qr, I received an error message €œRun Time Error €˜1001€ unable to get MMult property of the worksheetFunction.class. €œnc€ is 8 in the following. Can anyone help? Note, I wrote a very simple VBA routine to multiply a 3X3 times a 3X1 matrix and called the resultant matrix €œC€. C should be of dimensions 3X1. I included a MsgBox(C(1)) and the program hung up. When I changed it to MsgBox(C(1,1)), the program ran. Note, C was dimensioned (as a 1X3) €¦ Dim C(1 To 3) array. Sub Qmatrix() ReDim vr(1 To nc), vi(1 To nc), Qr(1 To nc), Qi(1 To nc), Pinv(1 To nc, 1 To nc) Pinv() = Application.WorksheetFunction.MInverse(p()) For j = 1 To nc vr(j) = v(j) * Cos(va(j) * pi / 180) vi(j) = v(j) * Sin(va(j) * pi / 180) Next j Qr = Application.WorksheetFunction.MMult(Pinv, vr) Qi = Application.WorksheetFunction.MMult(Pinv, vi) End Sub "Dana DeLouis" wrote: How do I do matrix operations from within an Excel VBA macro? Hi. One way... Sub Demo() Dim a, m a = [{3,4; 5,6}] With WorksheetFunction m = .MMult(a, a) m = .MInverse(a) End With End Sub = = = = = = = HTH :) Dana DeLouis Kirby Holte wrote: How do I do matrix operations from within an Excel VBA macro? Specifically matrix multiplication (MULT) and matrix inversion (MINVERT). *** Sent via Developersdex http://www.developersdex.com *** |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
out of memory problem! what to do for large matrix operations? | Excel Programming | |||
Matrix Operations in VBA | Excel Programming | |||
Matrix operations with complex numbers | Excel Discussion (Misc queries) | |||
Matrix Operations (MInvert Function) | Excel Programming | |||
VBA for matrix operations | Excel Programming |