# A Better Gradient 1.0

OS : Windows / Linux / Mac OS / BSD / Solaris

Script Licensing : Freeware

Created : Aug 18, 2007

Downloads : 5

Thank you for voting...

## GRADIENT2(F,X) returns the numerical gradient dF/dX ...

GRADIENT2(F, X) returns the numerical gradient dF/dX for vectors F and X. X need NOT be EQUALLY spaced. If X is not given, X=1:length(F) is assumed.

GRADIENT2(F, X) when F is a matrix returns the numerical gradient dF/dX over each column of F. X need NOT be equally spaced. The number of elements in X must equal the number of rows in F, i. e. , size(F, 1). If X is not given, X=1:size(F, 1) is assumed.

[dFx, dFy]=GRADIENT2(F, X, Y) when F is a matrix returns the 2D numerical gradients dFx = dF/dx and dFy = dF/dy, where vector X contains the x-axis data points and vector Y contains the y-axis data points. X and Y need NOT be EQUALLY spaced. The number of elements in X must equal the number of columns in F. The number of elements in Y must equal the number of rows in F. If X and Y are not given, X=1:size(F, 2) and Y=1:size(F, 1) are assumed.

[dFx, dFy]=GRADIENT2(F, X, Y) when X and Y are matrices the same size as F assumes that X and Y are 2D plaid as produced by [X, Y]=MESHGRID(x, y).

[dFx, dFy]=GRADIENT2(F, Dx, Dy) for scalar Dx and Dy, assumes that Dx and Dy are the X-axis and Y-axis data spacings respectively.

Algorithm: To support non equally spaced X and MATLAB vectorization, a quadratic polynomial fitting approach is taken. A second order polynomial is fit to each sequence of three consecutive data points, e. g. , X(i-1), X(i), and X(i 1) for i=2:length(X)-1. The slope of this polynomial is then computed at X(i-1), X(i), and X(i 1). Using this approach, one slope is computed at X(1) and X(end), giving a second order gradient on the edges. Two polynomial slopes are computed at X(2) and X(end).

Three polynomial slopes are computed at all other interior points. These slopes are optimally weighted for equally spaced data to give the gradient at interior points. For unequally spaced data, the weighting is close to optimal. This doesn't fit any textbook algorithm, but is easily implemented in MATLAB. Accuracy is typically an order of magnitude greater than the function GRADIENT.

GRADIENT2(F, X) when F is a matrix returns the numerical gradient dF/dX over each column of F. X need NOT be equally spaced. The number of elements in X must equal the number of rows in F, i. e. , size(F, 1). If X is not given, X=1:size(F, 1) is assumed.

[dFx, dFy]=GRADIENT2(F, X, Y) when F is a matrix returns the 2D numerical gradients dFx = dF/dx and dFy = dF/dy, where vector X contains the x-axis data points and vector Y contains the y-axis data points. X and Y need NOT be EQUALLY spaced. The number of elements in X must equal the number of columns in F. The number of elements in Y must equal the number of rows in F. If X and Y are not given, X=1:size(F, 2) and Y=1:size(F, 1) are assumed.

[dFx, dFy]=GRADIENT2(F, X, Y) when X and Y are matrices the same size as F assumes that X and Y are 2D plaid as produced by [X, Y]=MESHGRID(x, y).

[dFx, dFy]=GRADIENT2(F, Dx, Dy) for scalar Dx and Dy, assumes that Dx and Dy are the X-axis and Y-axis data spacings respectively.

Algorithm: To support non equally spaced X and MATLAB vectorization, a quadratic polynomial fitting approach is taken. A second order polynomial is fit to each sequence of three consecutive data points, e. g. , X(i-1), X(i), and X(i 1) for i=2:length(X)-1. The slope of this polynomial is then computed at X(i-1), X(i), and X(i 1). Using this approach, one slope is computed at X(1) and X(end), giving a second order gradient on the edges. Two polynomial slopes are computed at X(2) and X(end).

Three polynomial slopes are computed at all other interior points. These slopes are optimally weighted for equally spaced data to give the gradient at interior points. For unequally spaced data, the weighting is close to optimal. This doesn't fit any textbook algorithm, but is easily implemented in MATLAB. Accuracy is typically an order of magnitude greater than the function GRADIENT.

**• MATLAB Release: R14SP2**

**Demands:****A Better Gradient 1.0 scripting tags:**better gradient, spaced, points, matlab mathematics, matlab gradient, data, polynomial, computed, number.

**What is new in A Better Gradient 1.0 software script?**- Unable to find A Better Gradient 1.0 news.

**What is improvements are expecting?**Newly-made A Better Gradient 1.1 will be downloaded from here. You may download directly. Please write the reviews of the A Better Gradient. License limitations are unspecified.