-2
$\begingroup$

I have a function f(z,x),but it is a list of data. It is also in two variables z and x that are lists of data too.

I need to find gradient f(z,x). In another word, how I find a numerical differentiation of the function.

you can say I have a table or a matrix and my data is as below The first column is the values of variable z and the second column represents the values of variable x and the third column is the values of F which is a function in z and x. I need to find gradient F

{{0.025, 0.075, 0.0207689}, {0.0255, 0.075, 0.0237671}, {0.026, 0.075,
   0.026823}, {0.0265, 0.075, 0.0299193}, {0.027, 0.075, 
  0.0330451}, {0.0275, 0.075, 0.0361931}, {0.028, 0.075, 
  0.0393583}, {0.0285, 0.075, 0.042537}, {0.029, 0.075, 
  0.0457267}, {0.0295, 0.075, 0.0489254}, {0.03, 0.075, 
  0.0521317}, {0.025, 0.0755, 0.0210318}, {0.0255, 0.0755, 
  0.0240474}, {0.026, 0.0755, 0.0271155}, {0.0265, 0.0755, 
  0.0302207}, {0.027, 0.0755, 0.0333529}, {0.0275, 0.0755, 
  0.0365055}, {0.028, 0.0755, 0.039674}, {0.0285, 0.0755, 
  0.0428551}, {0.029, 0.0755, 0.0460463}, {0.0295, 0.0755, 
  0.049246}, {0.03, 0.0755, 0.0524526}, {0.025, 0.076, 
  0.0212976}, {0.0255, 0.076, 0.0243293}, {0.026, 0.076, 
  0.0274088}, {0.0265, 0.076, 0.0305221}, {0.027, 0.076, 
  0.0336603}, {0.0275, 0.076, 0.0368172}, {0.028, 0.076, 
  0.0399887}, {0.0285, 0.076, 0.0431719}, {0.029, 0.076, 
  0.0463645}, {0.0295, 0.076, 0.0495649}, {0.03, 0.076, 
  0.0527719}, {0.025, 0.0765, 0.0215661}, {0.0255, 0.0765, 
  0.0246126}, {0.026, 0.0765, 0.0277027}, {0.0265, 0.0765, 
  0.0308236}, {0.027, 0.0765, 0.0339672}, {0.0275, 0.0765, 
  0.037128}, {0.028, 0.0765, 0.0403023}, {0.0285, 0.0765, 
  0.0434874}, {0.029, 0.0765, 0.0466812}, {0.0295, 0.0765, 
  0.0498822}, {0.03, 0.0765, 0.0530894}, {0.025, 0.077, 
  0.021837}, {0.0255, 0.077, 0.0248973}, {0.026, 0.077, 
  0.0279971}, {0.0265, 0.077, 0.031125}, {0.027, 0.077, 
  0.0342736}, {0.0275, 0.077, 0.037438}, {0.028, 0.077, 
  0.0406149}, {0.0285, 0.077, 0.0438016}, {0.029, 0.077, 
  0.0469964}, {0.0295, 0.077, 0.050198}, {0.03, 0.077, 
  0.0534053}, {0.025, 0.0775, 0.0221102}, {0.0255, 0.0775, 
  0.0251832}, {0.026, 0.0775, 0.028292}, {0.0265, 0.0775, 
  0.0314263}, {0.027, 0.0775, 0.0345795}, {0.0275, 0.0775, 
  0.0377472}, {0.028, 0.0775, 0.0409263}, {0.0285, 0.0775, 
  0.0441146}, {0.029, 0.0775, 0.0473103}, {0.0295, 0.0775, 
  0.0505123}, {0.03, 0.0775, 0.0537195}, {0.025, 0.078, 
  0.0223855}, {0.0255, 0.078, 0.0254702}, {0.026, 0.078, 
  0.0285873}, {0.0265, 0.078, 0.0317275}, {0.027, 0.078, 
  0.0348849}, {0.0275, 0.078, 0.0380556}, {0.028, 0.078, 
  0.0412368}, {0.0285, 0.078, 0.0444263}, {0.029, 0.078, 
  0.0476228}, {0.0295, 0.078, 0.050825}, {0.03, 0.078, 
  0.0540322}, {0.025, 0.0785, 0.0226628}, {0.0255, 0.0785, 
  0.0257583}, {0.026, 0.0785, 0.0288829}, {0.0265, 0.0785, 
  0.0320285}, {0.027, 0.0785, 0.0351898}, {0.0275, 0.0785, 
  0.0383632}, {0.028, 0.0785, 0.0415462}, {0.0285, 0.0785, 
  0.0447368}, {0.029, 0.0785, 0.0479339}, {0.0295, 0.0785, 
  0.0511363}, {0.03, 0.0785, 0.0543433}, {0.025, 0.079, 
  0.0229419}, {0.0255, 0.079, 0.0260472}, {0.026, 0.079, 
  0.0291788}, {0.0265, 0.079, 0.0323294}, {0.027, 0.079, 
  0.0354942}, {0.0275, 0.079, 0.03867}, {0.028, 0.079, 
  0.0418545}, {0.0285, 0.079, 0.0450462}, {0.029, 0.079, 
  0.0482437}, {0.0295, 0.079, 0.0514462}, {0.03, 0.079, 
  0.0546529}, {0.025, 0.0795, 0.0232227}, {0.0255, 0.0795, 
  0.026337}, {0.026, 0.0795, 0.029475}, {0.0265, 0.0795, 
  0.03263}, {0.027, 0.0795, 0.035798}, {0.0275, 0.0795, 
  0.038976}, {0.028, 0.0795, 0.0421619}, {0.0285, 0.0795, 
  0.0453544}, {0.029, 0.0795, 0.0485523}, {0.0295, 0.0795, 
  0.0517547}, {0.03, 0.0795, 0.0549611}, {0.025, 0.08, 
  0.0235051}, {0.0255, 0.08, 0.0266276}, {0.026, 0.08, 
  0.0297714}, {0.0265, 0.08, 0.0329305}, {0.027, 0.08, 
  0.0361013}, {0.0275, 0.08, 0.0392812}, {0.028, 0.08, 
  0.0424684}, {0.0285, 0.08, 0.0456615}, {0.029, 0.08, 
  0.0488596}, {0.0295, 0.08, 0.0520619}, {0.03, 0.08, 0.0552679}}
$\endgroup$
  • $\begingroup$ It would be helpful to show the data (or some small part of it) $\endgroup$ – mikado Oct 24 '16 at 21:13
  • $\begingroup$ Use Interpolation $\endgroup$ – Bob Hanlon Oct 24 '16 at 21:18
  • $\begingroup$ See this, this, this, and this. $\endgroup$ – corey979 Oct 24 '16 at 21:25
2
$\begingroup$

Your data comes from a plane:

plot = ListPointPlot3D[data, {PlotStyle -> {Blue, PointSize[Large]}}]

enter image description here

so you can fit a plane to the data:

f[z_, x_] = Normal @ NonlinearModelFit[data, a x + b z + d, {a, b, d}, {z, x}]

{{zmin, zmax}, {xmin, xmax}} = MinMax /@ Transpose[data][[1 ;; 2]];

plot2 = Plot3D[Evaluate@f[z, x], {z, zmin, zmax}, {x, xmin, xmax}]

This shows how well the points lie on the fitted plane:

Show[plot, plot2]

enter image description here

Having a functional form of f[z,x] you can use Grad:

Grad[f[z, x], {z, x}]

{6.32646, 0.606243}


In general, one can use Interpolation:

int = Interpolation@data

e.g.

int[0.0272, 0.0799]

0.0373115

The gradient

grad = Grad[int[z, x], {z, x}]

in this case is a 2D vector function of z, x given by InterpolatingFunctions that can be plottted

GraphicsRow @ {Plot3D[grad[[1]], {z, zmin, zmax}, {x, xmin, xmax}], 
  Plot3D[grad[[2]], {z, zmin, zmax}, {x, xmin, xmax}]}

enter image description here

Up to the order of magnitude, this is consistent with the Grad of f[z,x].


This shows the differences between fitting a plane and interpolating the function:

diff = MapThread[
   Insert[#1, #2, 3] &, {data[[All, 1 ;; 2]], 
    f[##] & @@@ data[[All, 1 ;; 2]] - data[[All, 3]]}];

ListPlot3D[diff]

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.