Hi there,
I want to calculate multidimensional gradient of a scalar field. After I got to know the difference between meshgrid and ndgrid (general n-dimensional), I noticed that gradient calculates inconsistently when using with ndgrid.
While meshgrid assumes first dimension as y and second dimension as x, ndgrid does it the other way around (x first, y second). The gradient function does it the same way as meshgrid. Obviously, gradient and meshgrid belong together somehow.
But what should I do to calculate gradients consistently with n dimensions?
Example:
[mshx,mshy,mshz] = ndgrid(0:.1:10,0:.1:10,0:.1:10);[gxx,gyx,gzx] = gradient(mshx);[gxy,gyy,gzy] = gradient(mshy);[gxz,gyz,gzz] = gradient(mshz);
Here all gij are zero except gyx, gxy and gzz.
Is there an elegant way to do that kind of calculus to finally get all gij equal zero except for gxx, gyy, gzz?
Thank you for your help.
Best regards
Michael
Best Answer