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

Hello,
Let me try posting this again. I am trying to do some simple matrix
manipulation in vba. What I want to do is take a 4x4 matrix, invert
it, multiply a 4x1 column vector by the inverted matrix, and then put
the result into a column vector. I do not want to use ranges for the
inputs. I will put the matrix values into the matrix manually.

A is 4x4 matrix
B is 4x1 column
C is 4x1 column

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

Here is how the matrices are established. The variables come from
worksheet cells (not shown)
A(1, 1) = x1 ^ 3
A(2, 1) = x2 ^ 3
A(3, 1) = 3 * x1 ^ 2
A(4, 1) = 3 * x2 ^ 2

A(1, 2) = x1 ^ 2
A(2, 2) = x2 ^ 2
A(3, 2) = x1 * 2
A(4, 2) = x2 * 2

A(1, 3) = x1
A(2, 3) = x2
A(3, 3) = 1
A(4, 3) = 1

A(1, 4) = 1
A(2, 4) = 1
A(3, 4) = 0
A(4, 4) = 0

B(1) = y1
B(2) = y2
B(3) = m1
B(4) = m2

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

Here is my code:
C=MInverse(A)
C=MMult(C,B)

The code stops at the MMult(C,B) line, stating "Unable to get the
MMult property of the worksheetfunction class."

This seems to be a simple problem. Can anyone help me with this. An
example would be great.
thanks,
Andy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Matrix manipulation in vba code

Here is my code:
C=MInverse(A)
C=MMult(C,B)
The code stops at the MMult(C,B) line,


Hi. The functions are part of WorksheetFunction in Vba, as shown below.
The error, as my guess, is that your dimensions are off.
In Help, note the requirements for Rows and Columns between the two arrays.
Here's a demo. I wrote it like this to save space.

Sub Demo()
Dim A As Variant
Dim B As Variant
Dim C As Variant

A = [{2,2,1,3;1,3,4,4;5,4,1,5;5,4,3,4}]
B = [{5;4;3;2}] 'Make sure vertical x;y...
With WorksheetFunction
If Abs(.MDeterm(A)) < 0.0000000001 Then
MsgBox "A is Singular"
Exit Sub
End If

C = .MInverse(A)
C = .MMult(C, B)

'// iF Horizontal (x,y...
B = [{5,4,3,2}]
'// Then it would work with...
C = .MMult(B, C)

End With
End Sub


= = =
HTH :)
Dana DeLouis



Andrew wrote:
Hello,
Let me try posting this again. I am trying to do some simple matrix
manipulation in vba. What I want to do is take a 4x4 matrix, invert
it, multiply a 4x1 column vector by the inverted matrix, and then put
the result into a column vector. I do not want to use ranges for the
inputs. I will put the matrix values into the matrix manually.

A is 4x4 matrix
B is 4x1 column
C is 4x1 column

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

Here is how the matrices are established. The variables come from
worksheet cells (not shown)
A(1, 1) = x1 ^ 3
A(2, 1) = x2 ^ 3
A(3, 1) = 3 * x1 ^ 2
A(4, 1) = 3 * x2 ^ 2

A(1, 2) = x1 ^ 2
A(2, 2) = x2 ^ 2
A(3, 2) = x1 * 2
A(4, 2) = x2 * 2

A(1, 3) = x1
A(2, 3) = x2
A(3, 3) = 1
A(4, 3) = 1

A(1, 4) = 1
A(2, 4) = 1
A(3, 4) = 0
A(4, 4) = 0

B(1) = y1
B(2) = y2
B(3) = m1
B(4) = m2

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

Here is my code:
C=MInverse(A)
C=MMult(C,B)

The code stops at the MMult(C,B) line, stating "Unable to get the
MMult property of the worksheetfunction class."

This seems to be a simple problem. Can anyone help me with this. An
example would be great.
thanks,
Andy

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Matrix manipulation in vba code

I should have mentioned that if you want to do it similar to your code,
just adjust vector B like this...

Sub Demo()
Dim A As Variant
Dim B(1 To 4, 1 To 1)
Dim C As Variant

A = [{2,2,1,3;1,3,4,4;5,4,1,5;5,4,3,4}]

B(1, 1) = 5
B(2, 1) = 4
B(3, 1) = 3
B(4, 1) = 2

With WorksheetFunction
If Abs(.MDeterm(A)) < 0.0000000001 Then
MsgBox "A is Singular"
Exit Sub
End If

C = .MInverse(A)
C = .MMult(C, B)
End With
End Sub

= = =
HTH :)
Dana DeLouis
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
For better Performance in VBA for Excel - Strings manipulation OR Objects manipulation vmegha Excel Programming 2 December 19th 05 12:14 AM
Generating Code in Excel / Macro Recorder Manipulation [email protected] Excel Programming 2 August 18th 05 03:31 PM
Code for Access file manipulation from Excel Tom Urtis Excel Programming 0 July 21st 05 08:31 AM
VBA code manipulation cells Craig[_21_] Excel Programming 2 April 10th 05 10:06 AM
Halting code for worksheet manipulation? What-a-Tool[_2_] Excel Programming 2 November 5th 04 12:09 AM


All times are GMT +1. The time now is 01:21 PM.

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

About Us

"It's about Microsoft Excel"