Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
out of memory problem! what to do for large matrix operations? MCM[_2_] Excel Programming 4 June 18th 06 02:11 PM
Matrix Operations in VBA [email protected] Excel Programming 7 November 17th 05 02:07 PM
Matrix operations with complex numbers Veritas Excel Discussion (Misc queries) 1 July 22nd 05 06:30 PM
Matrix Operations (MInvert Function) Al[_16_] Excel Programming 1 November 23rd 04 07:29 PM
VBA for matrix operations Jules[_3_] Excel Programming 1 September 24th 03 02:14 AM


All times are GMT +1. The time now is 03:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"