Passing matrix to function

Hello everyone,

I'm working on a simple electrical circuit simulator and at some point it is necessary to calculate the inverse of some matrix in which its size depends on other parameters.

The solution I'm trying is setting up a user defined size matrix and then passing it to a blackbox function. This function however, takes pointers to input and output matrices as parameters and it doesn't seem to be very happy to accept my matrices.

Any suggestion will be most appreciated.
The most common issue in this kind of problem is over running your array. Are you using any of the STL Containers? It may make things easier for you to manage. Can we see some code?
show us the code, your pos doesn't realy tell us much about the matrixes and that stuff
why do you want to code it yourself, when other have already done the job for you ??
get a C++ matrix library( may be from sourceforge) with a clear and useful documentation, and let them do the job :-)

than you may be able to do some thing similar to following

1
2
3
4
libraryName< value_type> a(3, 3), b ;
a >> 2, 1, 1, 6, 2, 1, -2, 2, 1;
cout<<a.inv();
 b = a.inv();


hope it helps
Last edited on
Hey guys,

first of all, thanks a lot for the replies.

I've actually worked my way around that. Since I'm dealing with a very particular matrix pattern (both upper triangular and lower Hessenberg), I built some algorithm to find the order n inverse matrices for this specific purpose. I also found a way over the used defined size thing playing with loops, I'm hopeful it's gonna work fine.
I may not fully understand the problem. I work with well defined matrices: 3x3 and 4x4.

If ever I would have to work with a matrix that may be other, I would definitely make it a struct or class, depending on how much access I would need, with the dimensions as members.

Topic archived. No new replies allowed.