I have a set of points like this: P = {{$x_1$,$y_1$,$f(x_1,y_1)$},{$x_2$,$y_2$,$f(x_2,y_2)$},...,{$x_n$,$y_n$,$f(x_n,y_n)$}}.

I want to plot them and also plot the derivative of that graph. How can I do this with Mathematica? Is there a simple way in Mathematica?

  • $\begingroup$ You can plot the points with ListPointPlot[P], although user variables should not begin with a capital. I don't know what you mean by "the derivative" in this context. $\endgroup$ – Alan Jun 21 '17 at 19:08
  • $\begingroup$ Derivative of what graph with respect to what? $\endgroup$ – thedude Jun 21 '17 at 19:08
  • $\begingroup$ If you have the function f only on discrete points, then you cannot simply derive them. What you need is some kind of numerical scheme and Mathematica has a lot of them built-in. One way is to interpolate your points by a smooth function and use the derivative of the interpolation function. If your points {x,y} are not on a grid, it is a bit trickier, but can be accomplished as well. Is it possible that you provide your points (or a list of example points)? $\endgroup$ – halirutan Jun 21 '17 at 19:17
  • $\begingroup$ @thedude and Alan, i have a large set of numerical values of the form ($x_i$,$y_i$,$f(x_i,y_i)$), where $x_i$ and $y_i$ are the independent variables and $f(x_i,y_i)$ depends on the both $x_i$ & $y_i$. I got its 3D plot through ListPlot3D now i want to plot the derivative of this 3D plot? Probably a partial derivative i think? $\endgroup$ – Usman Jun 21 '17 at 19:17
  • $\begingroup$ @halirutan Since i have a big data, so i give you the points for example: {{0., 0.384609, 0.999965, -0.399952, 0.0333553, -0.430301}, {0.587785, 0.853728, 0.804087, -0.862295, 0.614443, -0.878706}, {0.951057, 0.996752, 0.301074, -0.99527, 0.960835, -0.991475}, {0.951057, 0.75905, -0.316938, -0.748085, 0.94022, -0.725534}, {0.587785, 0.231417, -0.813891, -0.215158, 0.560473, -0.182464}, {0., -0.384609, -0.999965, 0.399952, -0.0333553, 0.430301}} $\endgroup$ – Usman Jun 21 '17 at 19:25

Since you don't give an example of P, I will use the following data:

data = Flatten[
    Table[{x, y, Sin[x y]}, {x, 0, 5, .1}, {y, 0, 5, .1}],

The data is on a structured grid, meaning there is data for every point on a rectangular mesh. Hence, we can just use Interpolation:

if = Interpolation[data]

InterpolatingFunction[{{0., 5.}, {0., 5.}}, <>]

Now, if we want to plot the x derivative, we can just differentiate the InterpolatingFunction:

dx = Derivative[1, 0][if]

InterpolatingFunction[{{0., 5.}, {0., 5.}}, <>]

We see that the result is another InterpolatingFunction. Plotting the InterpolatingFunction is simple:

Plot3D[dx[x, y], {x, 0, 5}, {y, 0, 5}]

enter image description here

Since we constructed the data using Sin[x y], we know that the x derivative is simply y Cos[x y]. Let's compare:

Plot3D[y Cos[x y], {x, 0, 5}, {y, 0, 5}]

enter image description here

  • $\begingroup$ Thank you. This is quite helpful. $\endgroup$ – Usman Jun 21 '17 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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