passing and declaring vectors and matrices?

S

sandwich_eater

What is the usual way to declare real (float) vectors and matrices?
What ways are there to pass them to them into a function (by ref, by
val, pointer) ?

this is what I have...
const int MAX_MAT_DIM = 200;
typedef double TMTMatrix [MAX_MAT_DIM][MAX_MAT_DIM];
typedef double TMTVector [MAX_MAT_DIM];

void myfunc1(TMTVector &y, TMTMatrix &A);
void myfunc2(TMTVector *y, TMTMatrix *A);

....

TMTMatrix A1, A2;

myfunc1(y, A1);
myfunc2(&y, &A2);

if u is changed in both myfuncs will A1 and A2 change?

Thanks,
Daniel
 
V

Victor Bazarov

What is the usual way to declare real (float) vectors and matrices?
What ways are there to pass them to them into a function (by ref, by
val, pointer) ?

this is what I have...
const int MAX_MAT_DIM = 200;
typedef double TMTMatrix [MAX_MAT_DIM][MAX_MAT_DIM];
typedef double TMTVector [MAX_MAT_DIM];

void myfunc1(TMTVector &y, TMTMatrix &A);
void myfunc2(TMTVector *y, TMTMatrix *A);

...

TMTMatrix A1, A2;

myfunc1(y, A1);
myfunc2(&y, &A2);

if u is changed in both myfuncs will A1 and A2 change?

What is 'y' here? What is 'u'? How can your question be answered
without knowing what the 'mufunc1' and 'myfunc2' do?

V
 
S

sandwich_eater

Sorry I meant 'A' not u. I only wrote these functions as examples. My
question is a general one about how to declare and pass vectors upto a
maximum dimension, or open size if that can be done.

Victor said:
What is the usual way to declare real (float) vectors and matrices?
What ways are there to pass them to them into a function (by ref, by
val, pointer) ?

this is what I have...
const int MAX_MAT_DIM = 200;
typedef double TMTMatrix [MAX_MAT_DIM][MAX_MAT_DIM];
typedef double TMTVector [MAX_MAT_DIM];

void myfunc1(TMTVector &y, TMTMatrix &A);
void myfunc2(TMTVector *y, TMTMatrix *A);

...

TMTMatrix A1, A2;

myfunc1(y, A1);
myfunc2(&y, &A2);

if u is changed in both myfuncs will A1 and A2 change?

What is 'y' here? What is 'u'? How can your question be answered
without knowing what the 'mufunc1' and 'myfunc2' do?

V
 
V

velthuijsen

What is the usual way to declare real (float) vectors and matrices?
What ways are there to pass them to them into a function (by ref, by
val, pointer) ?

Try std::vector<float> and std::vector<std::vector<float> >.
Then use pass by reference for passing them to functions.

[SNIP]
if A is changed in both myfuncs will A1 and A2 change?

Depends on what you mean by change but generally yes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,301
Messages
2,571,549
Members
48,295
Latest member
JayKillian
Top