Mathematica Numerical Derivatives in Mathematica

AI Thread Summary
To import data into Mathematica and calculate numerical derivatives, start by ensuring the data is formatted correctly as a list of pairs {{x1, f1}, {x2, f2}, ...}. Use the Interpolation function to create an interpolating function from your data. If you encounter errors, check for formatting issues, such as extra brackets. Once the interpolation is set up correctly, you can find where the first derivative equals zero. Instead of using NSolve, which is not suitable for this case, use FindRoot with the syntax f'[x] == 0 to solve for the x-value where the derivative is zero. This approach allows for accurate calculations based on the interpolated function.
Moonshine
Messages
31
Reaction score
0
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.
 
Physics news on Phys.org
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.
 
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!
 
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'
 

Similar threads

Replies
4
Views
3K
Replies
3
Views
2K
Replies
5
Views
3K
Replies
4
Views
3K
Replies
1
Views
3K
Replies
1
Views
2K
Replies
3
Views
8K
Replies
1
Views
2K
Replies
1
Views
2K
Back
Top