From user-return-27277-apmail-commons-user-archive=commons.apache.org@commons.apache.org Sat Mar 31 17:59:47 2012
Return-Path:
X-Original-To: apmail-commons-user-archive@www.apache.org
Delivered-To: apmail-commons-user-archive@www.apache.org
Received: from mail.apache.org (hermes.apache.org [140.211.11.3])
by minotaur.apache.org (Postfix) with SMTP id D86E49B71
for ; Sat, 31 Mar 2012 17:59:47 +0000 (UTC)
Received: (qmail 38583 invoked by uid 500); 31 Mar 2012 17:59:46 -0000
Delivered-To: apmail-commons-user-archive@commons.apache.org
Received: (qmail 38500 invoked by uid 500); 31 Mar 2012 17:59:46 -0000
Mailing-List: contact user-help@commons.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: "Commons Users List"
Delivered-To: mailing list user@commons.apache.org
Received: (qmail 38491 invoked by uid 99); 31 Mar 2012 17:59:46 -0000
Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136)
by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 31 Mar 2012 17:59:46 +0000
X-ASF-Spam-Status: No, hits=-0.0 required=5.0
tests=RCVD_IN_DNSWL_NONE,SPF_PASS
X-Spam-Check-By: apache.org
Received-SPF: pass (athena.apache.org: domain of sujit.pal@comcast.net designates 76.96.30.16 as permitted sender)
Received: from [76.96.30.16] (HELO qmta01.emeryville.ca.mail.comcast.net) (76.96.30.16)
by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 31 Mar 2012 17:59:37 +0000
Received: from omta24.emeryville.ca.mail.comcast.net ([76.96.30.92])
by qmta01.emeryville.ca.mail.comcast.net with comcast
id sHhz1i0011zF43QA1HzHsZ; Sat, 31 Mar 2012 17:59:17 +0000
Received: from cyclone.hsd1.ca.comcast.net ([98.248.19.5])
by omta24.emeryville.ca.mail.comcast.net with comcast
id sHyV1i00l06aREA8kHzGbQ; Sat, 31 Mar 2012 17:59:17 +0000
Content-Type: text/plain; charset=iso-8859-1
Mime-Version: 1.0 (Apple Message framework v1084)
Subject: Re: [math] Getting second derivative for discrete dataset
From: SUJIT PAL
In-Reply-To: <4F773B45.3070706@free.fr>
Date: Sat, 31 Mar 2012 10:59:14 -0700
Content-Transfer-Encoding: quoted-printable
Message-Id:
References: <4C5A6E50-B943-4779-86B7-249128F87946@comcast.net> <9d863c76-1904-424d-8ad6-c408d39b2f2d@email.android.com> <4F773B45.3070706@free.fr>
To: "Commons Users List"
X-Mailer: Apple Mail (2.1084)
X-Virus-Checked: Checked by ClamAV on apache.org
Thank you Luc, this is very useful. Definitely much easier than what I =
was thinking of doing :-).
-sujit
On Mar 31, 2012, at 10:13 AM, Luc Maisonobe wrote:
> Le 31/03/2012 01:31, SUJIT PAL a =E9crit :
>> Thanks Luc, thanks for getting back so quickly, and will wait for =
your information tomorrow.
>=20
> Hi Sujit,
>=20
> Sorry for the delay.
>=20
> If you know your sample points (xi, yi) are all separated by the same
> interval h (i.e x(i+1) =3D x(i) + h for all i), then you can compute =
any
> derivatives using the following method:
>=20
> First write down the series expansion of the function y =3D f(x):
>=20
> y(x + k * h) =3D y(x)
> + k * h * y'(x)
> + (k * h)^2 / 2 y''(x)
> + ...
> + (k * h)^n / n! yn(x)
> + ...
>=20
> Then you truncate this expression to at least include the derivative =
you
> want, and apply it to a number of points equal to your truncation =
order.
> Here, as an example, we will truncate just to order 2 in order to have
> y'', so we have three components (y, y' and y''), so we need three
> points. Let's take k =3D -1, k =3D 0 and k =3D 2. We have the =
following
> expressions:
>=20
> y(x - h) =3D y(x) - h y'(x) + h^2/2 y''(x)
> y(x) =3D y(x)
> y(x+h) =3D y(x) + h y'(x) + h^2/2 y''(x)
>=20
> Note that the first and last expression differ only in the sign of the
> odd terms h y'(x), the even terms (h^0 and h^2) have the same sign.
>=20
> You can rewrite these expressions as a simple square matrix vector
> multiplication:
>=20
> [ y(x-h) ] [ 1 -h h^2/2 ] [ y(x) ]
> [ y(x) ] =3D [ 1 0 0 ] * [ y'(x) ]
> [ y(x+h) ] [ 1 h h^2/2 ] [ y''(x) ]
>=20
> Then you invert this system and get:
>=20
> [ y(x) ] [ 0, 1, 0 ] [ y(x-h) ]
> [ y'(x) ] =3D [ -1 / 2h, 0, 1 / 2h ] * [ y(x) ]
> [ y''(x) ] [ 1 / h^2, -2 / h^2, 1 / h^2] [ y(x+h) ]
>=20
> The third row is the one you want:
>=20
> y''(x) =3D (y(x-h) - 2 * y(x) + y(x+h)) / h^2
>=20
> You can check this formula using again the initial expansion, and you
> will see this combination basically canels out the y(x) and y'(x) part
> and only y''(x) remains.
>=20
> You could also have used more points, which could improve accuracy as =
it
> fits your function to an higher degree. Beware that you should *not*
> increase the number of points too much, otherwise you would get Gibbs
> oscillation problems (i.e a polynomial that has very large changes
> between the sampling points).
>=20
> Hope this helps
> Luc
>=20
>=20
>>=20
>> -sujit
>>=20
>> On Mar 30, 2012, at 2:36 PM, Luc Maisonobe wrote:
>>=20
>>>=20
>>>=20
>>>=20
>>> SUJIT PAL a =E9crit :
>>>=20
>>>> Hi,
>>>>=20
>>>> I have a (newbie) question about how to go about solving the =
problem
>>>> below with commons-math.
>>>>=20
>>>> 1) I have histogram data (equal x intervals) based off some
>>>> distribution.
>>>> 2) I need a way to calculate the second differential between two =
given
>>>> x points in the distribution.
>>>>=20
>>>> Here is what I think I should do:
>>>> 1) Feed the (x,y) values represented by the top of each histogram =
entry
>>>> within my x-range into a UnivariateRealInterpolator between ranges
>>>> (x1,y1) and (x2,y2).
>>>> 2) The interpolate method gives me back a PolynomialSplineFunction
>>>> (call if psf).
>>>> 3) I get the second differential UnivariateRealFunction (call it =
urf)
>>>> by calling psf.getPolynomialSplineDerivative().derivative()
>>>> 4) I compute the second derivative value as the difference of
>>>> urf.value(x2) - urf.value(x1)
>>>>=20
>>>> Does this sound like a reasonable/accurate approach? Any
>>>> suggestions/gotchas or pointers to better approaches?
>>>=20
>>> No, this is not an approach I would recommend. A much more =
straightforward
>>> way to compute this derivative is to apply a dedicated finite =
differences formula
>>> on three consecutive points. I'll give ou such a formula tomorrow (I =
am on a mobile
>>> device right now and it is difficult to write a compl=E8te mail...)
>>>=20
>>> Luc
>>>=20
>>>>=20
>>>> Thanks very much,
>>>>=20
>>>> Sujit
>>>>=20
>>>>=20
>>>> =
---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>=20
>>>=20
>>> =
---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>=20
>>=20
>>=20
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>=20
>=20
>=20
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>=20
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org