PC Review


Reply
Thread Tools Rate Thread

how array functions work mmult,minverse etc

 
 
ramki
Guest
Posts: n/a
 
      21st Feb 2006
can any one help me in writing my own code for this matrix functions?

please

 
Reply With Quote
 
 
 
 
vezerid
Guest
Posts: n/a
 
      21st Feb 2006
An array function must be entered in a group of cells. Let us say you
have a 2x3 matrix in A1:C2. Another 3x4 matrix in D1:G3. The result is
a 2x4 matrix. Decide where you want this matrix entered, say in A911.

Select A911
Type in the formula bar: =MMULT(A1:C2, D1:G3)
Press Shift+Ctrl+Enter

Excel will place the resulting matrix in these cells. From this point
on, A911 is a formula array and you can not delete part of it, only
the entire array (when in an formula array, Ctrl+/ will select the
entire array).

To edit, select the entire range, click in the formula bar, edit and
Shift+Ctrl+Enter again.

MINVERSE will work in a similar manner. Select the destination and
enter =MINVERSE(range). In this case of course, range must be a square
matrix as should the input.

HTH
Kostis Vezerides

 
Reply With Quote
 
ramki
Guest
Posts: n/a
 
      28th Feb 2006
hello thanks for the reply but what i want is something differrent i
want to see the internal coding i mean how mmult access variables in
the code and multiply in the code. can you help me in this regard?
vezerid wrote:
> An array function must be entered in a group of cells. Let us say you
> have a 2x3 matrix in A1:C2. Another 3x4 matrix in D1:G3. The result is
> a 2x4 matrix. Decide where you want this matrix entered, say in A911.
>
> Select A911
> Type in the formula bar: =MMULT(A1:C2, D1:G3)
> Press Shift+Ctrl+Enter
>
> Excel will place the resulting matrix in these cells. From this point
> on, A911 is a formula array and you can not delete part of it, only
> the entire array (when in an formula array, Ctrl+/ will select the
> entire array).
>
> To edit, select the entire range, click in the formula bar, edit and
> Shift+Ctrl+Enter again.
>
> MINVERSE will work in a similar manner. Select the destination and
> enter =MINVERSE(range). In this case of course, range must be a square
> matrix as should the input.
>
> HTH
> Kostis Vezerides


 
Reply With Quote
 
ramki
Guest
Posts: n/a
 
      28th Feb 2006

vezerid wrote:
> An array function must be entered in a group of cells. Let us say you
> have a 2x3 matrix in A1:C2. Another 3x4 matrix in D1:G3. The result is
> a 2x4 matrix. Decide where you want this matrix entered, say in A911.
>
> Select A911
> Type in the formula bar: =MMULT(A1:C2, D1:G3)
> Press Shift+Ctrl+Enter
>
> Excel will place the resulting matrix in these cells. From this point
> on, A911 is a formula array and you can not delete part of it, only
> the entire array (when in an formula array, Ctrl+/ will select the
> entire array).
>
> To edit, select the entire range, click in the formula bar, edit and
> Shift+Ctrl+Enter again.
>
> MINVERSE will work in a similar manner. Select the destination and
> enter =MINVERSE(range). In this case of course, range must be a square
> matrix as should the input.
>
> HTH
> Kostis Vezerides


 
Reply With Quote
 
vezerid
Guest
Posts: n/a
 
      2nd Mar 2006
Ramki

The following code will emulate MMULT(). I have included some error
checking so that you see the code for returning an Excel error value.
The code below is not necessarily the best available but it illustrates
to some degree how ranges and variables can communicate. Further work
would require search in the .programming newsgroup. Also, for more
explicit handling of array variables inside a VBA routine the online
help on the Dim statement will be a good start.

==============>

Option Base 1
Function MatrixMult(m1 As Range, m2 As Range) As Variant
Dim m 'This is the variable that will become an array and will be
returned
Dim a1, a2 'These are the variables into which we will read m1 and m2
Dim c As Range 'To be used in various checks.
' Error checking
' Any blanks or text in the cells?
For Each c In m1
If Not IsNumeric(c.Value) Or IsEmpty(c) Then
MatrixMult = CVErr(xlErrValue)
Exit Function
End If
Next c
For Each c In m2
If Not IsNumeric(c.Value) Or IsEmpty(c) Then
MatrixMult = CVErr(xlErrValue)
Exit Function
End If
Next c
' Do the two arrays have compatible dimensions?
If m1.Columns.Count <> m2.Rows.Count Then
MatrixMult = CVErr(xlErrValue)
End If

' Everything OK, now the operations
' First dimensionalize the output matrix
ReDim m(m1.Rows.Count, m2.Columns.Count)
' Assign the ranges to the variables. No ReDim necessary here b/c of
assignment
a1 = m1
a2 = m2
' Now the loop to calculate the output matrix
For i = LBound(a1, 1) To UBound(a1, 1)
For j = LBound(a2, 2) To UBound(a2, 2)
tot = 0
For k = LBound(a1, 2) To UBound(a1, 2)
tot = tot + a1(i, k) * a2(k, j)
Next k
m(i, j) = tot
Next j
Next i
' Finally we assign the matrix to the function name
MatrixMult = m
End Function

<=======================

HTH
Kostis Vezerides

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Logical functions AND,OR in array formulas work ? Tom Microsoft Excel Programming 4 17th Jan 2008 08:06 PM
Is there an array size limit for MMULT or MINVERSE in excel 2007? =?Utf-8?B?amltcjMxNQ==?= Microsoft Excel Worksheet Functions 4 7th Feb 2007 10:48 PM
TRANSPOSE and MMULT don't work together =?Utf-8?B?R2VvZmZyZXkgWmh1?= Microsoft Excel Worksheet Functions 1 10th Aug 2004 07:22 PM
Problem with MINVERSE and MMULT keith Microsoft Excel Worksheet Functions 8 8th Apr 2004 09:44 PM
VBA: Writing an array function (like MMult) fxmolden Microsoft Excel Programming 4 13th Nov 2003 07:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:35 PM.