Numerical Derivatives in Mathematica

In summary, the conversation discusses importing data into Mathematica and finding the y value where the first derivative is zero. The suggested method is to use an interpolating function and take derivatives of it. There is a discussion about the proper format for the data and an error that occurs. The solution is to use FindRoot to solve for the zero values.
  • #1
Moonshine
32
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
  • #2
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.
 
  • #3
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.
 
  • #4
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).
 
  • #5
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.
 
  • #6
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!
 
  • #7
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'
 

1. What is a numerical derivative in Mathematica?

A numerical derivative in Mathematica is a way to approximate the derivative of a function at a specific point using numerical methods. It allows for the quick and accurate calculation of derivatives without having to manually calculate them.

2. How do I calculate a numerical derivative in Mathematica?

To calculate a numerical derivative in Mathematica, you can use the N[D[f[x], x]] command, where f[x] represents the function you want to differentiate and x is the variable with respect to which you want to take the derivative. You can also specify the point at which you want to evaluate the derivative by adding a third argument, for example N[D[f[x], x] /. x->2] will evaluate the derivative of f[x] at x=2.

3. Can Mathematica calculate higher order numerical derivatives?

Yes, Mathematica can calculate higher order numerical derivatives using the N[D[f[x], {x, n}]] command, where n is the order of the derivative. For example, N[D[f[x], {x, 3}]] will calculate the third order derivative of f[x].

4. How accurate are numerical derivatives in Mathematica?

Numerical derivatives in Mathematica are generally very accurate, but the level of accuracy depends on the function being differentiated and the method used. It is recommended to use higher precision settings for more accurate results. You can also check the accuracy of the numerical derivative by comparing it to the analytical derivative, if possible.

5. Can I plot a numerical derivative in Mathematica?

Yes, you can plot a numerical derivative in Mathematica using the Plot command. For example, Plot[N[D[f[x], x]], {x, 0, 1}] will plot the numerical derivative of f[x] from x=0 to x=1. You can also plot multiple numerical derivatives on the same graph by using the Hold function, for example Plot[Hold[N[D[f[x], x]], N[D[f[x], {x, 2}]]], {x, 0, 1}].

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
406
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • Calculus and Beyond Homework Help
Replies
4
Views
692
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
Back
Top