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 multiplication A*B*A' , where
- A' refers to the transpose of matrix A
- matrix B is symmetric matrix.
- (optional) it will be much better if the result of (A*B) or (A*B)' can be stored as temperal matrix, as
this value is required thereafter.
I have been thinking about splitting matrix B into two parts,
such that : B = (L + L') , where L is the lower triangle matrix of B .
any hint or link or paper is welcomed !!!
danke
Joe
8 7848
You can multiply two matrices using three for loops, the first two are for the elements of the product matrix, and the third is for multiplying a row from the first matrix by a column from the second matrix(which will give you one of the elements of the product matrix).
It is like this: - for(int i=0;i<rows;i++)//rows is the number of rows in the first matrix
-
for(int j=0;j<cols;j++)//cols is the number of columns in the second matrix
-
for(int k=0;k<dim;k++)/*dim is the number of columns in the first matrix as well as the number of rows in the second matrix(since the number of columns of the first matrix is obigatory equal to the number of rows of the second matrix)*/
-
P[i][j]+=A[i][k]*B[k][j];//finds element P[i][j] of the product matrix P
As for multiplying three matrices, you can conclude what to do from the above.
Get the right tool for the job: use a linear algebra package. Have a look at GSL, or boost or blitz++.
The fact that B is symmetric does not lead to any simplifications as far as I can tell since A is arbitrary.
I have been thinking about splitting matrix B into two parts,
such that : B = (L + L') , where L is the lower triangle matrix of B .
Is diag(B) == 0?
kind regards,
Jos
thanks for all the responses !!!
You can multiply two matrices using three for loops, the first two are for the elements of the product matrix, and the third is for multiplying a row from the first matrix by a column from the second matrix(which will give you one of the elements of the product matrix).
It is like this: - for(int i=0;i<rows;i++)//rows is the number of rows in the first matrix
-
for(int j=0;j<cols;j++)//cols is the number of columns in the second matrix
-
for(int k=0;k<dim;k++)/*dim is the number of columns in the first matrix as well as the number of rows in the second matrix(since the number of columns of the first matrix is obigatory equal to the number of rows of the second matrix)*/
-
P[i][j]+=A[i][k]*B[k][j];//finds element P[i][j] of the product matrix P
As for multiplying three matrices, you can conclude what to do from the above.
yes, this is what I already have now. But it is kind of expensive as I am programming on an embedded system. I am looking for a compact version of that.
Get the right tool for the job: use a linear algebra package. Have a look at GSL, or boost or blitz++.
The fact that B is symmetric does not lead to any simplifications as far as I can tell since A is arbitrary.
thanks for the links. I will check them out. and it is true that matrix A is arbitrary.
Is diag(B) == 0?
kind regards,
Jos
sorry, I make a mistake . it should be like : B= L+L' + D , where D is the diagonal matrix.
sorry, I make a mistake . it should be like : B= L+L' + D , where D is the diagonal matrix.
I don't think that'll buy you much except that A*B*A == A*(L+L'+D)*A' ==
A*L*A'+A*L'*A'+A*D*A'; only A*L will be a common (transposed) factor; so
X = A*L then X*A'+A*X'+A*D*A'; now Y=X*A' will be the common (transposed)
factor so: Y+Y'+A*D*A'.
kind regards,
Jos
I don't think that'll buy you much except that A*B*A == A*(L+L'+D)*A' ==
A*L*A'+A*L'*A'+A*D*A'; only A*L will be a common (transposed) factor; so
X = A*L then X*A'+A*X'+A*D*A'; now Y=X*A' will be the common (transposed)
factor so: Y+Y'+A*D*A'.
kind regards,
Jos
thanks Jos,
I think this is the best way to implement the multiplication.
@arnaudk
Hi,
I am trying to use GSL library with my C++ program. Can you please tell what steps I need to take to link the library with bcc32 compiler. I have already installed GSL on my machine also I used IMPLIB.exe to link the gsl library to my prgram but it didn't work I used following command
Implib /Ic:/WinGnu32/lib libgsl.a libgsl.dll
Can you please guide me with step by step information how can I link GSL library to C++ program.
Cheers,
Hi, I wonder what solution did you end up using? Could you exploit that B is symmetric? Can you email me at msustik@gmail.com? I would really like to know more about the applicaion this came from. Thanks!
Matyas
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Daniel Wilcox |
last post by:
I have a question, I have been given a piece of code that
apparantly
compiles under Visual C++ but I cannot get to compile under
g++ 3.2.
I have read the FAQ and delved into the Stroustrup book...
|
by: Ben Ingram |
last post by:
Hi all,
I am writing a template matrix class in which the template parameters are
the number of rows and number of columns. There are a number of reasons
why this is an appropriate tradeoff for...
|
by: christopher diggins |
last post by:
Here is some code I wrote for Matrix multiplication for arbitrary
dimensionality known at compile-time. I am curious how practical it is. For
instance, is it common to know the dimensionality of...
|
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"....
|
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...
|
by: raylegendkiller |
last post by:
NEED TO MAKE A PROGRAM which computes the current value of the vectors {x}
based on the following forward iterations:
this >>> {x}(n+1) = {x}(n), n = 0,1,2, ... ,8,9.
In other...
|
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...
|
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"...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
| |