Thank you.
Suppose that I have a matrix M of dimension K and I want to calculate the partial derivation for each dimension of this matrix.
Then for dimension K I have to use K loops for each partial derivative
If K = 3:
Code:
for(i2=0 ; i2<N[2] ; i2++){
for(i1=0 ; i1<N[1] ; i1++){
for(i0=1 ; i0<N[0] ; i0++){
Dx0[i0-1][i1][i2] = M[i0][i1][i2] -M[i0-1][i1][i2] ;
}
}
}
Code:
for(i0=0 ; i0<N[0] ; i0++){
for(i2=0 ; i2<N[2] ; i2++){
for(i1=1 ; i1<N[1] ; i1++){
Dx1[i0][i1-1][i2] = M[i0][i1][i2] -M[i0][i1-1][i2] ;
}
}
}
Code:
for(i1=0 ; i1<N[1] ; i1++){
for(i0=0 ; i0<N[0] ; i0++){
for(i2=1 ; i2<N[2] ; i2++){
Dx2[i0][i1][i2-1] = M[i0][i1][i2] -M[i0][i1][i2-1] ;
}
}
}
I'm looking for a general method to decrease the amount of code.