Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Using matrices is vba code

Hello,
I am trying to do some simple matrix manipulation in vba. Here's what
I have:

A = 4x4 matrix, B = a 4x1 column, and C= a 4x1 column. declared as
Dim A(1 To 4, 1 To 4) As Double
Dim B(1 To 4) As Double
Dim C(1 To 4) As Double

What I want to do is invert A, then multiply it by B, and put the
results in C.

Functionally, my code is doing this... C = (A^1)*B
Of course vba doesn't understand what I want it to do. I have tried
to implement the code as

C=MInverse(A) - code won't get past here.
C=MMult(C,B)

Can someone send me an example of how to implement C = (A^1)*B

thanks,
Andy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Using matrices is vba code

One way:

Option Explicit
Sub testme()

Dim i As Long
Dim j As Long

Dim A(1 To 4, 1 To 4) As Double
Dim B(1 To 4) As Double
Dim C As Variant
Dim D As Variant

For i = LBound(A, 1) To UBound(A, 1)
For j = LBound(A, 2) To UBound(A, 2)
A(i, j) = Rnd
Next j
Next i

For i = LBound(B) To UBound(B)
B(i) = Rnd
Next i


With Application
C = .MInverse(A)
D = .MMult(C, .Transpose(B))

'or in one expression
D = .MMult(.MInverse(A), .Transpose(B))
End With

End Sub



Andrew wrote:

Hello,
I am trying to do some simple matrix manipulation in vba. Here's what
I have:

A = 4x4 matrix, B = a 4x1 column, and C= a 4x1 column. declared as
Dim A(1 To 4, 1 To 4) As Double
Dim B(1 To 4) As Double
Dim C(1 To 4) As Double

What I want to do is invert A, then multiply it by B, and put the
results in C.

Functionally, my code is doing this... C = (A^1)*B
Of course vba doesn't understand what I want it to do. I have tried
to implement the code as

C=MInverse(A) - code won't get past here.
C=MMult(C,B)

Can someone send me an example of how to implement C = (A^1)*B

thanks,
Andy


--

Dave Peterson
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
Sumproduct with Matrices Stacey Excel Discussion (Misc queries) 6 June 25th 07 02:39 PM
matrices Eiman Excel Discussion (Misc queries) 0 December 9th 05 11:01 PM
How to solve y =f(x,y) using matrices? Ane Excel Worksheet Functions 1 July 27th 05 02:37 AM
Combining certain matrices [email protected] Excel Discussion (Misc queries) 1 January 8th 05 12:06 AM
transpose matrices Mark Bigelow Excel Programming 0 August 1st 03 08:06 PM


All times are GMT +1. The time now is 08:29 AM.

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"