Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default UBound function does not work

I have defined two matrices InMatrix1 and InMatrix2 on a spredsheet by names.
The programme does not execute.
When I type UBound in the VBEditor, there is no prompt for the UBound word
after I press shift+spacebar.

What is the problem?
Function MatrixMult(InMatrix1 As Variant, InMatrix2 As Variant) As Variant

'generic matrix multiplication engine, pure BASIC code
Dim OutMatrix()
Dim i As Integer, k As Integer
Dim j As Integer
Dim Sum As Integer
ReDim OutMatrix(1 To UBound(InMatrix1, 1), 1 To UBound(InMatrix2, 2))

Application.Volatile 'force recalculation with spreadsheet

For i = 1 To UBound(InMatrix1, 1) 'rows of inmatrix1
For j = 1 To UBound(InMatrix2, 2) 'cols of inmatrix2
Sum = 0
For k = 1 To UBound(InMatrix1, 2)
Sum = Sum + InMatrix1(i, k) * InMatrix2(k, j)
Next
OutMatrix(i, j) = Sum
Next
Next

MatrixMult = OutMatrix

End Function


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default UBound function does not work

I forgot to address the question to the Experts.
Dear Experts, Please help.

Thank you so much for taking time to read the post. More thanks for
solutions,in advance.

"BEETAL" wrote:

I have defined two matrices InMatrix1 and InMatrix2 on a spredsheet by names.
The programme does not execute.
When I type UBound in the VBEditor, there is no prompt for the UBound word
after I press shift+spacebar.

What is the problem?
Function MatrixMult(InMatrix1 As Variant, InMatrix2 As Variant) As Variant

'generic matrix multiplication engine, pure BASIC code
Dim OutMatrix()
Dim i As Integer, k As Integer
Dim j As Integer
Dim Sum As Integer
ReDim OutMatrix(1 To UBound(InMatrix1, 1), 1 To UBound(InMatrix2, 2))

Application.Volatile 'force recalculation with spreadsheet

For i = 1 To UBound(InMatrix1, 1) 'rows of inmatrix1
For j = 1 To UBound(InMatrix2, 2) 'cols of inmatrix2
Sum = 0
For k = 1 To UBound(InMatrix1, 2)
Sum = Sum + InMatrix1(i, k) * InMatrix2(k, j)
Next
OutMatrix(i, j) = Sum
Next
Next

MatrixMult = OutMatrix

End Function


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default UBound function does not work

Hi

You can not pass two arrays to an UDF, so I have changed it to two ranges,
where the values will be processed.

I'm not sure what you expect to get as output. A function will only return
one value. As the function is working now it will return the value of the
first element in "OutMatrix".

Hopes it helps.

Public Function MatrixMult(InMatrix1 As Range, InMatrix2 As Range) As
Variant

'generic matrix multiplication engine, pure BASIC code
Dim OutMatrix()
Dim i As Integer, k As Integer
Dim j As Integer
Dim Sum As Integer
ReDim OutMatrix(1 To InMatrix1.Rows.Count, 1 To InMatrix2.Columns.Count)

Application.Volatile 'force recalculation with spreadsheet

For i = 1 To InMatrix1.Rows.Count 'rows of inmatrix1
For j = 1 To InMatrix2.Columns.Count 'cols of inmatrix2
Sum = 0
For k = 1 To InMatrix1.Columns.Count
Sum = Sum + InMatrix1.Cells(i, k) * InMatrix2.Cells(k, j)
Next
OutMatrix(i, j) = Sum
Next
Next

MatrixMult = OutMatrix

End Function

Best regards,
Per

"BEETAL" skrev i meddelelsen
...
I forgot to address the question to the Experts.
Dear Experts, Please help.

Thank you so much for taking time to read the post. More thanks for
solutions,in advance.

"BEETAL" wrote:

I have defined two matrices InMatrix1 and InMatrix2 on a spredsheet by
names.
The programme does not execute.
When I type UBound in the VBEditor, there is no prompt for the UBound
word
after I press shift+spacebar.

What is the problem?
Function MatrixMult(InMatrix1 As Variant, InMatrix2 As Variant) As
Variant

'generic matrix multiplication engine, pure BASIC code
Dim OutMatrix()
Dim i As Integer, k As Integer
Dim j As Integer
Dim Sum As Integer
ReDim OutMatrix(1 To UBound(InMatrix1, 1), 1 To UBound(InMatrix2, 2))

Application.Volatile 'force recalculation with spreadsheet

For i = 1 To UBound(InMatrix1, 1) 'rows of inmatrix1
For j = 1 To UBound(InMatrix2, 2) 'cols of inmatrix2
Sum = 0
For k = 1 To UBound(InMatrix1, 2)
Sum = Sum + InMatrix1(i, k) * InMatrix2(k, j)
Next
OutMatrix(i, j) = Sum
Next
Next

MatrixMult = OutMatrix

End Function



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default UBound function does not work


Dear Per Jessen,

tell you something! You must be a highly intelligent programmer. am i right
or not?

Thank You ,Sir.

as of now ,it works. I have hundreds of lines to pro gramme and debug. I
shall always expect to draw your kind attention to my doubts,hurdles(small
and big).

thanking you again,

with best regards

Siddhartha


"Per Jessen" wrote:

Hi

You can not pass two arrays to an UDF, so I have changed it to two ranges,
where the values will be processed.

I'm not sure what you expect to get as output. A function will only return
one value. As the function is working now it will return the value of the
first element in "OutMatrix".

Hopes it helps.

Public Function MatrixMult(InMatrix1 As Range, InMatrix2 As Range) As
Variant

'generic matrix multiplication engine, pure BASIC code
Dim OutMatrix()
Dim i As Integer, k As Integer
Dim j As Integer
Dim Sum As Integer
ReDim OutMatrix(1 To InMatrix1.Rows.Count, 1 To InMatrix2.Columns.Count)

Application.Volatile 'force recalculation with spreadsheet

For i = 1 To InMatrix1.Rows.Count 'rows of inmatrix1
For j = 1 To InMatrix2.Columns.Count 'cols of inmatrix2
Sum = 0
For k = 1 To InMatrix1.Columns.Count
Sum = Sum + InMatrix1.Cells(i, k) * InMatrix2.Cells(k, j)
Next
OutMatrix(i, j) = Sum
Next
Next

MatrixMult = OutMatrix

End Function

Best regards,
Per

"BEETAL" skrev i meddelelsen
...
I forgot to address the question to the Experts.
Dear Experts, Please help.

Thank you so much for taking time to read the post. More thanks for
solutions,in advance.

"BEETAL" wrote:

I have defined two matrices InMatrix1 and InMatrix2 on a spredsheet by
names.
The programme does not execute.
When I type UBound in the VBEditor, there is no prompt for the UBound
word
after I press shift+spacebar.

What is the problem?
Function MatrixMult(InMatrix1 As Variant, InMatrix2 As Variant) As
Variant

'generic matrix multiplication engine, pure BASIC code
Dim OutMatrix()
Dim i As Integer, k As Integer
Dim j As Integer
Dim Sum As Integer
ReDim OutMatrix(1 To UBound(InMatrix1, 1), 1 To UBound(InMatrix2, 2))

Application.Volatile 'force recalculation with spreadsheet

For i = 1 To UBound(InMatrix1, 1) 'rows of inmatrix1
For j = 1 To UBound(InMatrix2, 2) 'cols of inmatrix2
Sum = 0
For k = 1 To UBound(InMatrix1, 2)
Sum = Sum + InMatrix1(i, k) * InMatrix2(k, j)
Next
OutMatrix(i, j) = Sum
Next
Next

MatrixMult = OutMatrix

End Function




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default UBound function does not work

Hi Siddhartha

Thanks for your reply. I'm glad to help.

BTW: I'm not a programmer, I've just picked up a little knowledge of VBA
programming.

Best regards,
Per

"BEETAL" skrev i meddelelsen
...

Dear Per Jessen,

tell you something! You must be a highly intelligent programmer. am i
right
or not?

Thank You ,Sir.

as of now ,it works. I have hundreds of lines to pro gramme and debug. I
shall always expect to draw your kind attention to my doubts,hurdles(small
and big).

thanking you again,

with best regards

Siddhartha


"Per Jessen" wrote:

Hi

You can not pass two arrays to an UDF, so I have changed it to two
ranges,
where the values will be processed.

I'm not sure what you expect to get as output. A function will only
return
one value. As the function is working now it will return the value of the
first element in "OutMatrix".

Hopes it helps.

Public Function MatrixMult(InMatrix1 As Range, InMatrix2 As Range) As
Variant

'generic matrix multiplication engine, pure BASIC code
Dim OutMatrix()
Dim i As Integer, k As Integer
Dim j As Integer
Dim Sum As Integer
ReDim OutMatrix(1 To InMatrix1.Rows.Count, 1 To InMatrix2.Columns.Count)

Application.Volatile 'force recalculation with spreadsheet

For i = 1 To InMatrix1.Rows.Count 'rows of inmatrix1
For j = 1 To InMatrix2.Columns.Count 'cols of inmatrix2
Sum = 0
For k = 1 To InMatrix1.Columns.Count
Sum = Sum + InMatrix1.Cells(i, k) * InMatrix2.Cells(k, j)
Next
OutMatrix(i, j) = Sum
Next
Next

MatrixMult = OutMatrix

End Function

Best regards,
Per

"BEETAL" skrev i meddelelsen
...
I forgot to address the question to the Experts.
Dear Experts, Please help.

Thank you so much for taking time to read the post. More thanks for
solutions,in advance.

"BEETAL" wrote:

I have defined two matrices InMatrix1 and InMatrix2 on a spredsheet by
names.
The programme does not execute.
When I type UBound in the VBEditor, there is no prompt for the UBound
word
after I press shift+spacebar.

What is the problem?
Function MatrixMult(InMatrix1 As Variant, InMatrix2 As Variant) As
Variant

'generic matrix multiplication engine, pure BASIC code
Dim OutMatrix()
Dim i As Integer, k As Integer
Dim j As Integer
Dim Sum As Integer
ReDim OutMatrix(1 To UBound(InMatrix1, 1), 1 To UBound(InMatrix2, 2))

Application.Volatile 'force recalculation with spreadsheet

For i = 1 To UBound(InMatrix1, 1) 'rows of inmatrix1
For j = 1 To UBound(InMatrix2, 2) 'cols of inmatrix2
Sum = 0
For k = 1 To UBound(InMatrix1, 2)
Sum = Sum + InMatrix1(i, k) * InMatrix2(k, j)
Next
OutMatrix(i, j) = Sum
Next
Next

MatrixMult = OutMatrix

End Function







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default UBound function does not work

As a side note, are you aware of the function MMult?

Sub Demo()
Dim m, m1, m2
m1 = [{1,2;3,4;5,6}]
m2 = [{11,12,13;14,15,16}]

With WorksheetFunction
m = .MMult(m1, m2)
End With
End Sub

HTH
Dana DeLouis



BEETAL wrote:
Dear Per Jessen,

tell you something! You must be a highly intelligent programmer. am i right
or not?

Thank You ,Sir.

as of now ,it works. I have hundreds of lines to pro gramme and debug. I
shall always expect to draw your kind attention to my doubts,hurdles(small
and big).

thanking you again,

with best regards

Siddhartha


"Per Jessen" wrote:

Hi

You can not pass two arrays to an UDF, so I have changed it to two ranges,
where the values will be processed.

I'm not sure what you expect to get as output. A function will only return
one value. As the function is working now it will return the value of the
first element in "OutMatrix".

Hopes it helps.

Public Function MatrixMult(InMatrix1 As Range, InMatrix2 As Range) As
Variant

'generic matrix multiplication engine, pure BASIC code
Dim OutMatrix()
Dim i As Integer, k As Integer
Dim j As Integer
Dim Sum As Integer
ReDim OutMatrix(1 To InMatrix1.Rows.Count, 1 To InMatrix2.Columns.Count)

Application.Volatile 'force recalculation with spreadsheet

For i = 1 To InMatrix1.Rows.Count 'rows of inmatrix1
For j = 1 To InMatrix2.Columns.Count 'cols of inmatrix2
Sum = 0
For k = 1 To InMatrix1.Columns.Count
Sum = Sum + InMatrix1.Cells(i, k) * InMatrix2.Cells(k, j)
Next
OutMatrix(i, j) = Sum
Next
Next

MatrixMult = OutMatrix

End Function

Best regards,
Per

"BEETAL" skrev i meddelelsen
...
I forgot to address the question to the Experts.
Dear Experts, Please help.

Thank you so much for taking time to read the post. More thanks for
solutions,in advance.

"BEETAL" wrote:

I have defined two matrices InMatrix1 and InMatrix2 on a spredsheet by
names.
The programme does not execute.
When I type UBound in the VBEditor, there is no prompt for the UBound
word
after I press shift+spacebar.

What is the problem?
Function MatrixMult(InMatrix1 As Variant, InMatrix2 As Variant) As
Variant

'generic matrix multiplication engine, pure BASIC code
Dim OutMatrix()
Dim i As Integer, k As Integer
Dim j As Integer
Dim Sum As Integer
ReDim OutMatrix(1 To UBound(InMatrix1, 1), 1 To UBound(InMatrix2, 2))

Application.Volatile 'force recalculation with spreadsheet

For i = 1 To UBound(InMatrix1, 1) 'rows of inmatrix1
For j = 1 To UBound(InMatrix2, 2) 'cols of inmatrix2
Sum = 0
For k = 1 To UBound(InMatrix1, 2)
Sum = Sum + InMatrix1(i, k) * InMatrix2(k, j)
Next
OutMatrix(i, j) = Sum
Next
Next

MatrixMult = OutMatrix

End Function



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
Ubound matrix Arne Hegefors Excel Programming 7 October 12th 07 06:43 PM
Why is this returning a Ubound value of zero [email protected] Excel Discussion (Misc queries) 1 September 28th 07 07:44 PM
UBound Arturo Excel Programming 5 January 26th 07 04:06 PM
Array Ubound gti_jobert[_71_] Excel Programming 6 March 27th 06 10:34 PM
Ubound & Lbound Michael168[_80_] Excel Programming 3 June 1st 04 02:00 PM


All times are GMT +1. The time now is 11:24 AM.

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"