- Joined
- Mar 2, 2012
- Messages
- 1
- Reaction score
- 0
I am taking a matrix of size NxN and turning it into a long array to evaluate the velocity at many points in a domain. What I want to do is update the velocity using iterations to propagate the boundary conditions into the domain. In order to do this, I want to write a class that has member functions. I want one of these functions to pass the old values of the velocity array into the function, and use a pointer to return an updated array. I've read a few books and many online forums, and no one has provided a satisfactory solution.
This is what I've tried:
FUNCTION:
double *myClass::ReturnNewArray(double OldArray[], int length)
{
double *NewArray[length];
NewArray[0] = OldArray[0];
NewArray[length] = OldArray[length];
for (int i = 1; i < length; i++)
{
NewArray = OldArray + 0.5*(OldArray[i-1] + OldArray[i+1]);
}
return NewArray;
}
IN THE MAIN CPP File:
double length = 10, Velocity[length];
MyClass *NewVelocity[length];
Velocity = NewVelocity.ReturnNewArray(Velocity, length);
__________________________________________________________________
Can someone PLEASE help me? I would like a fairly detailed explanation so that I can thoroughly understand.
Additionally, if someone could help me understand how to make a void function that I can call that will update the array, that would be great. Or will the function always need to return type double (where my velocity will be a double type)?
This is what I've tried:
FUNCTION:
double *myClass::ReturnNewArray(double OldArray[], int length)
{
double *NewArray[length];
NewArray[0] = OldArray[0];
NewArray[length] = OldArray[length];
for (int i = 1; i < length; i++)
{
NewArray = OldArray + 0.5*(OldArray[i-1] + OldArray[i+1]);
}
return NewArray;
}
IN THE MAIN CPP File:
double length = 10, Velocity[length];
MyClass *NewVelocity[length];
Velocity = NewVelocity.ReturnNewArray(Velocity, length);
__________________________________________________________________
Can someone PLEASE help me? I would like a fairly detailed explanation so that I can thoroughly understand.
Additionally, if someone could help me understand how to make a void function that I can call that will update the array, that would be great. Or will the function always need to return type double (where my velocity will be a double type)?