1
$\begingroup$

Imagine I have a set of data, the plot is as following(just as an example consider a Gaussian curve): enter image description here

Is there any way to obtain the slop of this curve slop and plotted just using the initial data.

Thank alot

$\endgroup$
  • $\begingroup$ Do you have some example data? $\endgroup$ – Coolwater Jan 10 '18 at 15:39
  • $\begingroup$ And explain please, what is "the first plot in Mathematica"? $\endgroup$ – Alexei Boulbitch Jan 10 '18 at 15:46
  • $\begingroup$ @ Alexei Boulbitch I added an example, also by first data I meant the data I plotted the curve. $\endgroup$ – kmsin Jan 10 '18 at 15:54
  • $\begingroup$ @Coolwater I added an example. $\endgroup$ – kmsin Jan 10 '18 at 15:54
  • $\begingroup$ I want to plot the slop of this curve with his own data, is it possible? $\endgroup$ – kmsin Jan 10 '18 at 17:03
4
$\begingroup$

If you want to do it numerically with a dataset, say data

data = Table[{x, Exp[-x^2]}, {x, -5, 5, 0.1}];

you can go like this

ndata = Length[data];
slope = Table[{(data[[i, 1]] + data[[i - 1, 1]])/2, 
               (data[[i, 2]] - data[[i - 1, 2]])/(data[[i, 1]] - data[[i - 1, 1]]) },
              {i, 2, ndata}];
ListLinePlot[{data, slope}, PlotRange -> All]

enter image description here

Or you can go with Interpolation

f[x_] = Interpolation[data][x]; (*function for data*)
f1[x_] = D[f[x], x];            (*function for derivative*)
Plot[{f[x], f1[x]}, {x, -5, 5}]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks, I was looking for something the same as the second part of your answer $\endgroup$ – kmsin Jan 10 '18 at 19:11
  • $\begingroup$ In case you know any trial function for your data, you can also use Fit, FindFit or NonlinearModelFit to find a functional form. $\endgroup$ – Sumit Jan 11 '18 at 17:04

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.