k-Wave Toolbox |
Create a matrix of finite-difference coefficients
fdm = getFDMatrix(Nx) fdm = getFDMatrix(Nx, dx) fdm = getFDMatrix(Nx, dx, deriv_order, accuracy_order)
getFDMatrix
returns a matrix of finite-difference coefficients to compute the derivative of the given order with the given numerical accuracy. The coefficients in the center of the grid use centered differences, while the coefficients at the edges of the grid use forward and backward differences. The matrix is generated and returned in sparse format. To convert to a full matrix, use the syntax fdm = full(fdm).
Example: Compute the gradient of a 1D column vector
dx = pi/20; x = (0:dx:4*pi).'; y = sin(x); fdm = getFDMatrix(length(x), dx); dydx = fdm * y; plot(x, y, 'k-', x, dydx, 'r-');
|
size of data to differentiate |
|
spacing between grid points (default = 1) |
|
order of the derivative to compute, e.g., use 1 to compute df/dx, 2 to compute df^2/dx^2, etc. (default = 1) |
|
order of accuracy for the finite difference coefficients. Because centered differences are used, this must be set to an integer multiple of 2 (default = 2) |
|
matrix of finite difference coefficients |
gradient
, gradientFD
, gradientSpect
getDateString | getkWavePath |
© 2009-2014 Bradley Treeby and Ben Cox.