Numerical Integration of 2D data arrays

Joined
Oct 23, 2008
Messages
3
Reaction score
0
Dear all,

I have a 2D matrix M(x,y) and want to perform the integration M(x,y)dy. For performance concerns, I am using a FORTRAN-like representation of the matrix, which means my data are written in a 1D valarray as:

M(x0,y0) M(x1,y0) ... M(xN,y0) M(x0,y1) M(x1,y1) .... M(xN,yN).

To integrate the data, I'd use a function of the type:

Code:
double integrate(valarray<doube>* variable, valarray<doube>* integrand)
{
double result = 0;
// calculate
return result;
}

The caller for the integrate() function should pass it a pointer to the array containing the slice of the complete array M I am considering. The trivial implementation could be:

Code:
valarray<double> y // the integration variable
valarray<double> M // the complete matrix
slice s(first,length,stride);
valarray<double> thisSlice = M[s];
double result = integrate(&y, &thisSlice);

The problem here is the creation of a temporary copy. Since the slice can be quite large (and I do mean large), how would it be possible to avoid the temporary creation? An implementation like:

Code:
double result = integrate(&y, &(M[s]))

doesn't work unfortunately (error C2440: 'initializing' : cannot convert from 'std::slice_array<_Ty> *__w64 ' to 'compile_valarray *'... with VC++ 8.0).



Thanks & regards,

MrMF
 

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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top