473,473 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

multiplication of 3 matrix that produce 6x6 matrix

19 New Member
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
7 5380
kadghar
1,295 Recognized Expert Top Contributor
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
Killer42
8,435 Recognized Expert Expert
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
Killer42
8,435 Recognized Expert Expert
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
1,295 Recognized Expert Top Contributor
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
vbwire
19 New Member
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
1,295 Recognized Expert Top Contributor
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
vbwire
19 New Member
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

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

Similar topics

3
by: robix | last post by:
Hi again. I'm now asking your help because of a smal problem i'm getting with my multiplication matrix code. I'll try to give you as many details as possible. My matrix structure: typedef...
14
by: amitnanda | last post by:
Hi Guys, I have a matrix multiplication program in C that multiplies two matrices. When their size is 3*3 or 800*800, the program runs fine. But above that size, I get a "segmentation fault"....
0
by: lituncse | last post by:
dear friends, i have come across a problem which is difficult to solve for me.it's about starssen's matrix multiplication.in general matrix multiplication we need 8 multiplications and 4 additions...
1
emaghero
by: emaghero | last post by:
Does anybody know an algorithm for the fast multiplication of three n-x-n symmetric matrices? I have an algorithm, which I'm not too pleased with, that does the job. Does anybody know a faster...
6
by: amitsoni.1984 | last post by:
Hi, Is there any direct function for matrix multiplication in Python or any of its packages? or do we have to multiply element by element? Thank you, Amit
12
by: sugard | last post by:
I am a java beginner and I was given this task to do.. to create a class which given 2 matrices,and these bein of the correct dimensions, will produce a third matrix by multiplying both. There is the...
3
by: crazygrey | last post by:
Hello, I'm a newbie to C++ so excuse me if my question was trivial but it is important to me. I'm implementing a simple code to find the forward kinematics of a robot: #include "stdafx.h"...
1
by: Sozos | last post by:
Hi guys. I have a problem with writing the base case for the following matrix multiplication function I have implemented. Please help. #define index(i,j,power) (((i)<<(power))+(j)) void...
8
by: joegao1 | last post by:
can some one give me a hint? I want to program the code for matrix multiplication with as less arithmetical / multiplication operations as possible. my task is to calculate the matrix...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.