"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 = x2x1; x32 = x3x2; x43 = x4x3; x54 = x5x4;
x31 = x3x1; x42 = x4x2; x53 = x5x3;
x41 = x4x1; x52 = x5x2; x51 = x5x1;
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*(y2y1)/x21+w32*(y3y2)/x32+w43*(y4y3)/x43+w54*(y5y4)/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
