By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,994 Members | 2,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,994 IT Pros & Developers. It's quick & easy.

multiplication of 3 matrix that produce 6x6 matrix

P: 19
hi.. im new to programming world.im a first year student in computer graphics. i just curious how to multiply 3 matrices in a coding. i just can do the 2 matrices multiplication.but it is not a good coding too.. if someone there can help me,i'll be so glad to learn.for now i would like to learn the simple c or visual basic 6.0..
Jan 17 '08 #1
Share this Question
Share on Google+
7 Replies


kadghar
Expert 100+
P: 1,295
hi.. im new to programming world.im a first year student in computer graphics. i just curious how to multiply 3 matrices in a coding. i just can do the 2 matrices multiplication.but it is not a good coding too.. if someone there can help me,i'll be so glad to learn.for now i would like to learn the simple c or visual basic 6.0..
I see... well, im not suposed to do your homework, but i love making simple math functions, and this one is quite simple if you know the theory. So...lets say you have:

A = M m*n (matrix m by n)
B = M n*p
then (AB) = M m*p
where (AB)ij = SUM (r=1 to n) of (air * brj)

that in a single code, lets say you have Arr1 and Arr2, and both matrices start their both indexes at 1. To find Arr3 = (Arr1*Arr2) just do

Expand|Select|Wrap|Line Numbers
  1. dim i, j, n as integer
  2. dim Arr3() as double
  3. redim arr3(1 to ubound(arr1), 1 to ubound(arr2,2))
  4. for i = 1 to ubound(arr1)
  5.     for j = 1 to ubound(arr2,2)
  6.         for n = 1 to ubound(arr2)
  7.             arr3(i,j) = arr3(i,j) + (arr1(i,n) * arr2(n,j))
  8.         next
  9.     next
  10. next
YEAH!!!

Now, you know matrix multiplication is asociative, so...
(AB)C = A(BC)

so now we know that D = AB (or in our code Arr3 = Arr1 * Arr2)
and we want to have its product with C (lets say Arr4)
so just do Arr3 * Arr4 following the same procedure. just remember
if
A = M m*n
B = M n*p
C = M p*k
then
ABC = M m*k and n = n and p = p, always!
so if you want a 6x6 matrix as a result, make sure m=6 and k=6.

HTH
Jan 18 '08 #2

Expert 5K+
P: 8,434
I'd recommend you download and learn VB2005 or VB2008 (I think 2008 is still in Beta). They can both be downloaded for free from Microsoft. VB6 (which I personally like) is over ten years old and gradually dying out.
Jan 18 '08 #3

Expert 5K+
P: 8,434
Expand|Select|Wrap|Line Numbers
  1. dim i, j, n as integer
I just want to point out this mistake, which is probably just about the most commonly made in VB (prior to VB.Net).

This line does not define three Integer variables, as one might expect. It defines one Integer (n) and two (i and j)of the default data type, which is likely to be Variant (the most "expensive" data type available).

To do what you probably intended, it would need to be
Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer, j As Integer, n As Integer
Oh, and one more point. In V6 you should generally avoid the Integer data type and use Long instead. Unless you're really short of RAM.
Jan 18 '08 #4

kadghar
Expert 100+
P: 1,295
I just want to point out this mistake, which is probably just about the most commonly made in VB (prior to VB.Net).

This line does not define three Integer variables, as one might expect. It defines one Integer (n) and two (i and j)of the default data type, which is likely to be Variant (the most "expensive" data type available).

To do what you probably intended, it would need to be
Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer, j As Integer, n As Integer
Oh, and one more point. In V6 you should generally avoid the Integer data type and use Long instead. Unless you're really short of RAM.
didnt know that
thnks killer ^.^}

oh, and if you're working with a couple of matrices of over 1000x1000, its because you've got ram... i dont think someone its going to use a 32000x32000,
Jan 18 '08 #5

P: 19
I see... well, im not suposed to do your homework, but i love making simple math functions, and this one is quite simple if you know the theory. So...lets say you have:

A = M m*n (matrix m by n)
B = M n*p
then (AB) = M m*p
where (AB)ij = SUM (r=1 to n) of (air * brj)

that in a single code, lets say you have Arr1 and Arr2, and both matrices start their both indexes at 1. To find Arr3 = (Arr1*Arr2) just do

Expand|Select|Wrap|Line Numbers
  1. dim i, j, n as integer
  2. dim Arr3() as double
  3. redim arr3(1 to ubound(arr1), 1 to ubound(arr2,2))
  4. for i = 1 to ubound(arr1)
  5.     for j = 1 to ubound(arr2,2)
  6.         for n = 1 to ubound(arr2)
  7.             arr3(i,j) = arr3(i,j) + (arr1(i,n) * arr2(n,j))
  8.         next
  9.     next
  10. next
YEAH!!!

Now, you know matrix multiplication is asociative, so...
(AB)C = A(BC)

so now we know that D = AB (or in our code Arr3 = Arr1 * Arr2)
and we want to have its product with C (lets say Arr4)
so just do Arr3 * Arr4 following the same procedure. just remember
if
A = M m*n
B = M n*p
C = M p*k
then
ABC = M m*k and n = n and p = p, always!
so if you want a 6x6 matrix as a result, make sure m=6 and k=6.

HTH
thank you.. but im confius.sorry.. im still new to this.

i dont know what is ubound. i had learn only the basic of vb. ive learnt controls,simple calculations,loops,arrays.. can it be more easier? i get the concept of matrix but i confius with the coding..
Jan 18 '08 #6

kadghar
Expert 100+
P: 1,295
thank you.. but im confius.sorry.. im still new to this.

i dont know what is ubound. i had learn only the basic of vb. ive learnt controls,simple calculations,loops,arrays.. can it be more easier? i get the concept of matrix but i confius with the coding..
ubound (uper bound) is the size of the n-th dimension of an array, the default is the first dimension.

so if Arr1 is an array 10x15
ubound(arr1) = ubound(arr1,1) = 10
ubound(arr1, 2) = 15

you can also use lbound (lower bound) but since i was assuming they all started in 1 , lbound of anything will be always 1. but in real life, most of the arrays start in 0 so an array(10, 15) will be a matrix of 11x16.

HTH
Jan 18 '08 #7

P: 19
ubound (uper bound) is the size of the n-th dimension of an array, the default is the first dimension.

so if Arr1 is an array 10x15
ubound(arr1) = ubound(arr1,1) = 10
ubound(arr1, 2) = 15

you can also use lbound (lower bound) but since i was assuming they all started in 1 , lbound of anything will be always 1. but in real life, most of the arrays start in 0 so an array(10, 15) will be a matrix of 11x16.

HTH

waahh.. its helps.. so,we can put a limit to our program rite? how to limits it to a minimum type of matrix?i.e.. to make it produce at least 3x3 matrix..

so interesting..
Jan 20 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.