Re: how can one use mathematica get the approximate derivative of {x,y} data points?
- To: mathgroup at smc.vnet.net
- Subject: [mg124297] Re: how can one use mathematica get the approximate derivative of {x,y} data points?
- From: Murray Eisenberg <murray at math.umass.edu>
- Date: Mon, 16 Jan 2012 17:08:45 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
Using Interpolation to find an interpolation function for the discrete {x,y} data points is begging the question: what method of numerical approximation should one use. Unlike with numerical integration, good numerical differentiation is a very delicate matter. There are all kinds of schemes for doing it, from the very naive to the more sophisticated. The difficulty is that the methods are generally unstable: reducing the step-size to control truncation error typically allows the roundoff error to grow. At least, one must worry about what Interpolation is actually doing. The difficulty is perhaps highlighted by several features of this function: - you may specify in the argument not just the {x,y} values but also the intended values of the derivative at the x-values; - the option InterpolationOrder allows you to specify what order polynomials are used to interpolate (the default order being 3); and - interpolation has a Method option. In practice, Richardson extrapolation is often used for numerical differentiation. There's a nice introduction to this in Skeel and Kuiper's book "Elementary Numerical Computing with Mathematica." All that said, for the purposes of the O.P., naively using Interpolation may suffice. On 1/14/12 5:10 PM, Bob Hanlon wrote: > data = {#, Cos[#]}& /@ RandomReal[{0, 2 Pi}, 20]; > > f = Interpolation[data]; > > Plot[{f[x], f'[x]}, {x, Min[data[[All, 1]]], Max[data[[All, 1]]]}] > > > Bob Hanlon > > > On Sat, Jan 14, 2012 at 2:53 AM, Michael B. Heaney<mheaney at alum.mit.edu> wrote: >> Hi, >> >> I have a set of {x,y} data points: >> >> {{0.03512, -0.5}, {0.0351181, -0.499}, ... {-0.113972, 0.699}, {-0.115072, >> 0.7}} >> >> These data points look like a function y=f(x) when plotted on the x-y axes. >> However, I do not know what the function f(x) is. But I need to get the >> approximate derivative df/dx, as another set of data points. How can one >> use Mathematica to do this? >> >> Thanks, >> >> Michael >> > -- Murray Eisenberg murray at math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305