MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: how can one use mathematica get the approximate derivative of {x,y} data points?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124315] Re: how can one use mathematica get the approximate derivative of {x,y} data points?
  • From: Barrie Stokes <Barrie.Stokes at newcastle.edu.au>
  • Date: Mon, 16 Jan 2012 17:15:02 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

HI Michael

Here is one way, that I think is transparent enough for you to see what is happening:

(* create some data *)
data = Table[ {x, Sin[ Exp[ x ] ]}, {x, 0, 1.7, 0.05} ]

(* visualize the underlying function *)
p1 = ListPlot[ data ];
p2 = ListPlot[ data, Joined -> True, PlotStyle -> {PointSize[ 0.5 ]} ];
Show[ {p1, p2} ]

(* create an InterpolatingFunction object for this data *)
interp = Interpolation[ data, InterpolationOrder -> 5,   Method -> "Spline" ]

(* check that it looks right, i.e., represents the data *)
p3 = Plot[ interp[x], {x, 0, 1.7} ];
Show[ {p1, p3} ]

(* create a derivative of this InterpolatingFunction object for this \
data *)interpD[x_] := \!\(
\*SubscriptBox[\(\[PartialD]\), \(t\)]\ \(interp[t]\)\) /. {t -> x}
interpD[x]

(* visualize the derivative *)
p4 = Plot[ interpD[x], {x, 0, 1.7} ]

(* the true derivative behind our data *)
\!\(\*SubscriptBox[\(\[PartialD]\), \(x\)]\ \(Sin[\ Exp[\ x\ ]\ \ ]\)\)

p5 = Plot[ E^x Cos[E^x], {x, 0, 1.7} ]

(* the derivative of the Interpolation gives a good approximation *)
p6 = Plot[ E^x Cos[E^x] - interpD[x], {x, 0, 1.7} ]

(* create a list of derivative values at the original abscissae *)
dataD = Table[ {x, interpD[x]}, {x, 0, 1.7, 0.02} ]

You'll doubtless get a variety of suggestions, as this is a fairly straightforward task for an experienced Mathematican.

Best

Barrie

>>> On 14/01/2012 at 6:53 pm, in message <201201140753.CAA01265 at smc.vnet.net>,
"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
> 
> --




  • Prev by Date: Re: How to simplify this code with variable number of
  • Next by Date: Re: How to check whether an infinite set is closed under addition?
  • Previous by thread: how can one use mathematica get the approximate derivative of {x,y} data points?
  • Next by thread: Re: how can one use mathematica get the approximate derivative of {x,y} data points?