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..
 
Share this Question
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  dim i, j, n as integer

dim Arr3() as double

redim arr3(1 to ubound(arr1), 1 to ubound(arr2,2))

for i = 1 to ubound(arr1)

for j = 1 to ubound(arr2,2)

for n = 1 to ubound(arr2)

arr3(i,j) = arr3(i,j) + (arr1(i,n) * arr2(n,j))

next

next

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
  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.
  Expert 5K+
P: 8,434

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  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.
  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  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,
 
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  dim i, j, n as integer

dim Arr3() as double

redim arr3(1 to ubound(arr1), 1 to ubound(arr2,2))

for i = 1 to ubound(arr1)

for j = 1 to ubound(arr2,2)

for n = 1 to ubound(arr2)

arr3(i,j) = arr3(i,j) + (arr1(i,n) * arr2(n,j))

next

next

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..
  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 nth 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
 
P: 19

ubound (uper bound) is the size of the nth 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..
    Question stats  viewed: 4951
 replies: 7
 date asked: Jan 17 '08
