F
fivelitermustang
I have two matrices allocated dynamically in both directions: matrix x and
matrix v.
I want to pass these matrices into a function by reference. What I have
written down isn't working... can somebody enlighten me on how I would
solve this?
Here is what my prototype and my function look like:
=====================================================
double distance(int k, int i, int& n, double *x[], double *v[]);
double distance(int k, int i, const int& n, double *x[], double *v[])
{
double w;
for (int j=0; j<n; j++)
{
w = w + pow((x[k][j] - v[j]), 2);
}
return w;
}
In addition, I have another question. Is it possible to call this function
by only using the first two parameters (i and k)?
"x" and "v" are the matrices that are being read in and they will always
be used. "n" is a set constant at the beginning of the program that isn't
changed. It would clean up the code if I could just say "distance(i, k)"
and the other three variables would automatically be used.
As it sits now, this is how the function would be called (given that I
could get that double pointer issue sorted out... LOL!)
double q = 0;
for (int i=0; i<C; i++)
{
for (int k=0; k<Nm; k++)
{
q = q + pow((u[k]),m)*distance(k, i, n, x, v);
}
}
Any help would be greatly appreciated.
matrix v.
I want to pass these matrices into a function by reference. What I have
written down isn't working... can somebody enlighten me on how I would
solve this?
Here is what my prototype and my function look like:
=====================================================
double distance(int k, int i, int& n, double *x[], double *v[]);
double distance(int k, int i, const int& n, double *x[], double *v[])
{
double w;
for (int j=0; j<n; j++)
{
w = w + pow((x[k][j] - v[j]), 2);
}
return w;
}
In addition, I have another question. Is it possible to call this function
by only using the first two parameters (i and k)?
"x" and "v" are the matrices that are being read in and they will always
be used. "n" is a set constant at the beginning of the program that isn't
changed. It would clean up the code if I could just say "distance(i, k)"
and the other three variables would automatically be used.
As it sits now, this is how the function would be called (given that I
could get that double pointer issue sorted out... LOL!)
double q = 0;
for (int i=0; i<C; i++)
{
for (int k=0; k<Nm; k++)
{
q = q + pow((u[k]),m)*distance(k, i, n, x, v);
}
}
Any help would be greatly appreciated.