Numerical Derivatives in Mathematica

Click For Summary

Discussion Overview

The discussion revolves around calculating numerical derivatives of data imported into Mathematica, specifically focusing on finding the y value where the first derivative equals zero. Participants explore methods for data interpolation and derivative calculation, addressing challenges faced by a beginner user.

Discussion Character

  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant suggests using an interpolating function to facilitate the calculation of derivatives and to find where they equal zero.
  • Another participant recommends using Interpolation instead of InterpolatingFunction, noting the expected data format.
  • A participant expresses confusion regarding an error message encountered when attempting to use Interpolation, indicating a potential issue with the data format.
  • One participant reports resolving an issue related to extra brackets in the data, leading to successful output from the Interpolation function.
  • A later reply advises using FindRoot instead of NSolve for solving the equation related to the first derivative.
  • Areas of Agreement / Disagreement

    Participants present multiple approaches to the problem, with some disagreement on the appropriate methods for interpolation and solving for the derivative. The discussion remains unresolved as participants continue to refine their approaches.

    Contextual Notes

    Limitations include potential misunderstandings about the required data format for interpolation and the specific functions to use for solving equations in Mathematica.

    Who May Find This Useful

    Users of Mathematica, particularly those interested in numerical analysis, data interpolation, and derivative calculations.

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 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
8K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 9 ·
Replies
9
Views
4K