Re: discrete numerical 2D gradient
- To: mathgroup at smc.vnet.net
- Subject: [mg114492] Re: discrete numerical 2D gradient
- From: Sebastian Schmitt <sschmitt at physi.uni-heidelberg.de>
- Date: Sun, 5 Dec 2010 21:55:46 -0500 (EST)
Hi! Mark McClure wrote: > On Tue, Oct 12, 2010 at 1:49 PM, Sebastian Schmitt > <sschmitt at physi.uni-heidelberg.de> wrote: > >> I have 2D data represented as a matrix. I would like to obtain the >> gradient. >> ... >> Is there a better (both mathematical and Mathematical) to construct the >> y-derivatives (dyMatrix)? > > I would use ListInterpolation on your dataMatrix. The result is an > InterpolatingFunction that you can manipulate in all sorts of ways. > > dataMatrix = Table[i*j, {i, 10}, {j, 10}]; > f = ListInterpolation[dataMatrix, {{0, 1}, {0, 1}}]; > grad[x_, y_] = {Derivative[1, 0][f][x, y], > Derivative[0, 1][f][x, y]}; > VectorPlot[grad[x, y], {x, 0, 1}, {y, 0, 1}] grad[x_, y_] = D[f[x, y], {{x, y}}]; is possible as well. Cheers, Sebastian