# Numerical Derivatives in Mathematica

• Mathematica

## Main Question or Discussion Point

I have some data in a text file. I want to import this data into Mathematica, and then I want to calculate the numerical derivatives of this data. In particular, I need to find the y value where the first derivative is equal to zero.

I can import data. I can use the ND function for numerical derivativess, but I'm unsure how to accomplish the rest.

The data follows a sine curve with increasing amplitude. Do I need to fit the data first somehow?

Any help is appreciated. I'm kind of a beginner when it comes to Mathematica.

Related MATLAB, Maple, Mathematica, LaTeX News on Phys.org
Dale
Mentor
I would use an interpolating function. You can take derivatives of interpolated functions which would allow you to simply solve for where they equal 0.

Thanks, but I'm having a problem still.

I have my data imported, and I plotted it using ListPlot. It is a sin like curve with increasing amplitude as the x-values increase.

I'm thinking that the data is not in the form that InterpolationFunction expects.

I'm pretty new to mathematica, so any help is appreciated.

Dale
Mentor
Don't use InterpolationFunction, use just Interpolation. It expects the data in the form {{x1,f1},{x2,f2},...} where xi is the ith x-value and fi is the corresponding value f(xi).

I tried that one too, but I receive the following error:

Interpolation::inder :
The order-2 derivative of {0.08028, 0.01704} is not a tensor of rank 2 with dimensions 2.>>

I'm not sure what this means. Thanks for your help.

Okay, I think I have it working now.

My data had an extra { at the beginning and the end. Now, when I type

f = Interpolation[data]

The output is

InterpolatingFunction[{{0.02007,10.035}},<>]

Which I believe is the proper output.

Now, can I've tried the following code to get the zero values, and I think it is wrong.

NSolve[f' == 0, x]

Any help is appreciated. Thanks!

Dale
Mentor
You will want to use FindRoot instead of NSolve, and you need to put in an x before you can solve for it. E.g. f'[x] instead of f'