Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Numerical Derivatives in Mathematica

  1. Jan 31, 2010 #1
    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.
     
  2. jcsd
  3. Jan 31, 2010 #2

    Dale

    Staff: 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.
     
  4. Feb 2, 2010 #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.
     
  5. Feb 2, 2010 #4

    Dale

    Staff: 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).
     
  6. Feb 2, 2010 #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.
     
  7. Feb 2, 2010 #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!
     
  8. Feb 2, 2010 #7

    Dale

    Staff: 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'
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook