Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
High order discrete differenciation schemes

Subject: High order discrete differenciation schemes

From: John Deas

Date: 21 Jan, 2009 15:07:01

Message: 1 of 3

Hi,

I used the builtin gradient function to quickly compute partial derivatives in a matrix representing my evenly spaced data (I am working on entropy production in heat exchangers). Gradient use a first order centered derivative, and I would like to check the sensibility of the final results of my computation against other discretisation scheme and order.

It seems that there is a possibility to model data using splines then differentiate it, and, increasing the order of the spline will increase the differentiation order.

As this is a collateral aspect of my research, I would like to know if sombedy can point out to a readily available solution to the problem ?

Subject: High order discrete differenciation schemes

From: Roger Stafford

Date: 21 Jan, 2009 17:14:02

Message: 2 of 3

"John Deas" <john.deas.smash.spam@gmail.com> wrote in message <gl7dml$cdd$1@fred.mathworks.com>...
> Hi,
>
> I used the builtin gradient function to quickly compute partial derivatives in a matrix representing my evenly spaced data (I am working on entropy production in heat exchangers). Gradient use a first order centered derivative, and I would like to check the sensibility of the final results of my computation against other discretisation scheme and order.
>
> It seems that there is a possibility to model data using splines then differentiate it, and, increasing the order of the spline will increase the differentiation order.
>
> As this is a collateral aspect of my research, I would like to know if sombedy can point out to a readily available solution to the problem ?

  Here is the quartic formula for first derivative estimates. If a curve goes through the five points (x1,y1), (x2,y2), (x3,y3), (x4,y4), and (x5,y5), (presumably with x1 < x2 < x3 < x4 < x5), then the quartic estimate for the derivative dy/dx at x = x3 is:

x21 = x2-x1; x32 = x3-x2; x43 = x4-x3; x54 = x5-x4;
x31 = x3-x1; x42 = x4-x2; x53 = x5-x3;
x41 = x4-x1; x52 = x5-x2; x51 = x5-x1;
w21 = -x32*x43*x53/x31/x41/x51;
w32 = (x31*x41*(x31+x52)+x32*x52*(x31+x42))*x43*x53/x31/x42/x41/x52/x51;
w43 = (x53*x52*(x53+x41)+x43*x41*(x53+x42))*x32*x31/x53/x42/x41/x52/x51;
w54 = -x32*x43*x31/x53/x52/x51;
dy/dx3 = w21*(y2-y1)/x21+w32*(y3-y2)/x32+w43*(y4-y3)/x43+w54*(y5-y4)/x54;

  It is easy to write this in vectorized form for vectors. At the endpoints it is not necessary to have x1 through x5 in ascending order. The same formula works with them out of order, so for example you can have x3 < x4 < x5 < x1 < x2 and get a valid fourth order estimate for the derivative at x3.

  Also I think you will find some file exchange programs that do fourth order differentiation. The formula rapidly increases in complexity as the order goes up.

Roger Stafford

Subject: High order discrete differenciation schemes

From: John D'Errico

Date: 21 Jan, 2009 18:25:18

Message: 3 of 3

"John Deas" <john.deas.smash.spam@gmail.com> wrote in message <gl7dml$cdd$1@fred.mathworks.com>...
> Hi,
>
> I used the builtin gradient function to quickly compute partial derivatives in a matrix representing my evenly spaced data (I am working on entropy production in heat exchangers). Gradient use a first order centered derivative, and I would like to check the sensibility of the final results of my computation against other discretisation scheme and order.
>
> It seems that there is a possibility to model data using splines then differentiate it, and, increasing the order of the spline will increase the differentiation order.
>
> As this is a collateral aspect of my research, I would like to know if sombedy can point out to a readily available solution to the problem ?

If you have the spines toolbox, this takes
not much more than a call to fnder after the
spline interpolant is chosen.

If you don't have the splines toolbox, then you
have two options. One is the high order finite
difference approximations, which you would
need to code yourself. The second option is
a Savitsky-Golay filter. I can offer my own
movingslope code from the file exchange. It
allows you to control the order of the method.

In my code, if you specify supportlength such
that it is 1 more than modelorder, then the code
will effectively use a Lagrange interpolating
polynomial to estimate your derivatives. For
example, a 4th order model, with a corresponding
supportlength of 5, will give you an implicit
sliding quartic polynomial fit. The effective
order of the derivative estimator will be 4.

A 2nd order model, with a support length of
3 will yield the standard central finite difference
approximation for the derivative.

http://www.mathworks.com/matlabcentral/fileexchange/16997

I believe there are other Savitsky-Golay variants
on the FEX too.

HTH,
John

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us