473,698 Members | 2,923 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

matrix equation in C

Hi,

How to represent this matrix equation in C code:

/ a0 \ / 0 1 0 1 0 0 1 0 \/ b0 \
| a1 | | 0 0 1 0 1 0 0 1 || b1 |
| a2 | | 1 0 0 1 0 1 0 0 || b2 |
| a3 |=| 0 1 0 0 1 0 1 0 || b3 |
| a4 | | 0 0 1 0 0 1 0 1 || b4 |
| a5 | | 1 0 0 1 0 0 1 0 || b5 |
| a6 | | 0 1 0 0 1 0 0 1 || b6 |
\ a7 / \ 1 0 1 0 0 1 0 0 /\ b7 /

Regards,

-- Tiza Naziri --

Nov 14 '05 #1
5 2904
In article <11************ *********@f14g2 000cwb.googlegr oups.com>,
Tiza Naziri <wa****@yahoo.c om> wrote:
How to represent this matrix equation in C code:


[ 8 x 8 matrix multiplication shown ]

Depends -- do you need to do the calculation symbolically
or numerically? Are b0 thru b7 integers or floating point?
Are the matrix coefficients always going to be 0's and 1's with
no other possible values? Are you always going to be doing 8x8
or will the size be variable? Is the maximum size and density
enough that sparse representations seem like a good idea?
Are you solving for a[*] (matrix multiplication) or b[*] (matrix
division)? Is stability of the matrix inverse a significant concern?
Is there a good reason to impliment the manipulation yourself instead
of using one of the well-established libraries such as BLAS
or SCSL?

One hint: If you are doing the math yourself, then watch out for
the memory layout that C uses for multidimensiona l arrays, which
is different than the memory layout traditionally used by Fortran.
Pay attention to the memory layout when you are chosing which
index to loop over most quickly.

And if you get into very big matrices that might not fit in primary
cache, and you are implimenting by yourself, read up on matrix blocking
techniques.

Another hint: especially when your matrices have 2^N elements, watch
out for cache line aliasing -- if the array positions in memory are
seperated by a multiple of the cache line size, then something
seemingly simple such as

X[i][J] = Y[i][J];

might require a cache load to fetch the value from Y, and then might
require that the -same- cache line be dumped and loaded with the
corresponding position in X in order to do the store; whereas if
the starting positions of the arrays are carefully positioned to be
on different cache lines, then a cache-line's worth of data from Y
could be transfered to X before having to load cache again.
[Having a large primary cache doesn't help if the program's memory
access keeps thrashing over cache-line access...]
Anything to do with caches is outside the scope of the C89 standard.
Generally speaking pre-written libraries such as BLAS have been written
to take such matters into account, and so can sometimes end up being orders
of magnitude faster than naive code. It doesn't usually pay to
redevelop the mistakes of the past: it's usually best to find a
reputable matrix library that already does what you need.

A reference book for such matters: "Numerical Algorithms in C".
--
Any sufficiently old bug becomes a feature.
Nov 14 '05 #2
Do you need to do the calculation symbolically
or numerically?
--> numerically..

Are b0 thru b7 integers or floating point?
--> b0 - b7 are integers of 0's and 1's..

Are the matrix coefficients always going to be 0's and 1's with
no other possible values?
--> yes (relates to previous question)..

Are you always going to be doing 8x8
or will the size be variable?
--> only 8x8 matrix

Are you solving for a[*] (matrix multiplication) or b[*] (matrix
division)?
--> a[*]

Any suggestion on this matter?

Regards.

-- Tiza Naziri --

Nov 14 '05 #3
In article <11************ *********@f14g2 000cwb.googlegr oups.com>,
Tiza Naziri <wa****@yahoo.c om> wrote:

How to represent this matrix equation in C code:

/ a0 \ / 0 1 0 1 0 0 1 0 \/ b0 \
| a1 | | 0 0 1 0 1 0 0 1 || b1 |
| a2 | | 1 0 0 1 0 1 0 0 || b2 |
| a3 |=| 0 1 0 0 1 0 1 0 || b3 |
| a4 | | 0 0 1 0 0 1 0 1 || b4 |
| a5 | | 1 0 0 1 0 0 1 0 || b5 |
| a6 | | 0 1 0 0 1 0 0 1 || b6 |
\ a7 / \ 1 0 1 0 0 1 0 0 /\ b7 /


How about this:

a0 = b1 + b3 + b6;
a1 = b2 + b4 + b7;
a2 = b0 + b3 + b5;
...

If this is not what you meant, then you will have
to be more explicit about your requirements.

--
Rouben Rostamian
Nov 14 '05 #4
In article <11************ *********@f14g2 000cwb.googlegr oups.com>,
Tiza Naziri <wa****@yahoo.c om> wrote:
--> b0 - b7 are integers of 0's and 1's.. Are the matrix coefficients always going to be 0's and 1's with --> only 8x8 matrix Are you solving for a[*] (matrix multiplication) Any suggestion on this matter?


In the one special case of coefficients which are 0's and 1's,
multiplication is equivilent to bitwise AND, and you can carry
out the multiplications on groups at a time.

The below assumes that unsigned char is 8 bits or wider (which is
promised by the standard). If you needed to do larger matrices, you
could use wider datatypes than unsigned char.

#define MATSIZE 8

int sumbits( unsigned char v ) {
unsigned char t = v & 1;
unsigned char w = v >> 1;
int j;

for (j = 0; j < MATSIZE-1; j++ ) {
t += w & 1;
w >>= 1;
}

return t;
}

int main(void) {
unsigned char a[MATSIZE], M[MATSIZE];
unsigned char b;

init_M( M );
init_b( &b );

for (i = 0; i < MATSIZE; i++)
a[i] = sumbits( M[i] & b );

print_vec( a );
}
--
Would you buy a used bit from this man??
Nov 14 '05 #5
Yes, but I want programming suggestions as written by walter.. Anyway,
thanks walter!

Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
8918
by: Stud Muffin | last post by:
Hey Basically, I'm trying to take objects created in microsoft word using equation editor (for creating clean looking math/physics equations) and putting them into some sort of webpage format. But they come out grossly unalligned and ugly when I try to directly copy and paste into microsoft frontpage 2000. Few things I could do is place them directly using x/y coord (which i don't know how to do), or just taking screenshots and use...
13
5853
by: Havatcha | last post by:
Does anyone know of a decent (free/easy to use) C++ library for manipulating matrices and caculating eigenvalues, eigenvectors and so on? I intend to add some Principal Component Analysis functionality to some software. Any recommendations appreciated.
1
4016
by: hello12 | last post by:
hello, i have 2 upper triangular matrices A and B.. the values are stored in efficient format in the text file. I wanted to use those values for matrix multiplication and display the result C on the screen. I am supposed to use 1d arrays. SO, basically i have 2 --> 1d arrays which i am supposed to multiply to get C.C must not store zeroes(i.e it must also be in efficient format). I am having trouble in the multiplication part... i am...
14
6213
by: Paul McGuire | last post by:
I've posted a simple Matrix class on my website as a small-footprint package for doing basic calculations on matrices up to about 10x10 in size (no theoretical limit, but performance on inverse is exponential). Includes: - trace - transpose - conjugate - determinant - inverse - eigenvectors/values (for symmetric matrices)
5
3071
w33nie
by: w33nie | last post by:
My table is pretty well complete, but I would prefer it if the value for Points could be turned into a mathematical equation, and this equation would use the data from the other fields in the table to achieve a value. I want this done in phpMyAdmin 2.7, if possible, so that when I change the values in other fields, the Points variable changes, due to its equation. The equation I would want would be something like: "won * 3 + drawn * 1"...
6
14843
by: Trev17 | last post by:
Hello, I am new to C++ and i have tried for several hours to make a program my teacher has given me as a lab. Here is the Lab question: the roots of the quadratic equation ax^2 + bx + c = 0, a cannot equal 0 are given by the following formula -b + or - square root of (b^2 - 4ac) / 2a. If b^2 - 4ac = 0 then equation has a single root. if b^2 - 4ac > 0 then equation has two real roots. if b^2 - 4ac < 0 then equation has two complex...
0
2092
by: Bas | last post by:
On Sep 22, 10:02 am, Al Kabaila <akaba...@pcug.org.auwrote: That argument might have been valid 3 years ago, but as already said by others, Numeric and Numarray are deprecated. Numpy should be the only thing needed for new users. I suggest you investigate a little bit more the next time you make such efforts, since this fact should be widely known among the users of the mentioned packages, see e.g. the huge warning at the numarray page:...
10
2364
by: Constantine AI | last post by:
Hi i am having a little problem with an equation function that was created from all your help previously. The function works fine itself but with a small glitch within it. Here is the function code. Public Function fCalcEquation(strEquation As String) As Long Dim MyDB As DAO.Database Dim rstParameters As DAO.Recordset Dim intParamPosition As Integer Dim strParameter As String Dim strValue As String
2
3759
by: phoenix1990 | last post by:
so i have an entry frame where i want to input an equation, and i need to turn the string into an actual equation in terms of x. so that i can plot it on a canvas. i already know how to make the entry frame, and how to extract the string equation that was inputed. the only problem i'm having is converting it into an actual equation. e.g. the string input is 'sin(x)' and i want to turn it into sin(x) x is defined by another entry frame...
0
9170
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8902
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7740
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
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 we have to send another system
2
2339
muto222
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.