File Exchange

image thumbnail

diffCenterVar

version 1.0.0.0 (2.66 KB) by Matthew Kelly
1st and 2nd derivatives, non-uniform time grid, second-order method

6 Downloads

Updated 19 Jul 2016

View License

% [dx, ddx] = diffCenterVar(t,x);
%
% Computes first and second derivatives of x(t)
% --> Second-order accurate
% --> Works for non-uniform grid
%
% INPUTS:
% t = [1,m] = time grid
% x = [n,m] = function values for each point on the grid
%
% OUTPUTS:
% dx = [n,m] = first derivative of x
% ddx = [n,m] = second derivative of x
%
% NOTES:
% This function works by locally fitting a quadratic curve between each
% set of three points. See Derive_Eqns.m for details.
%

Comments and Ratings (1)

Simple fix for endpoints compared to Matlab's gradient.m.
For a drop-in replacement, redefine the gradient function:
gradient = @(x,t) reshape(diffCenterVar(t(:).', x(:).'), size(x));

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: diffCenter