Michael Thomas Flanagan's Java Scientific Library

Gradient Class:     Gradients in 1- and 2-Dimensional Arrays

     

Last update: 12 September 2012                                                                                                                              Main Page of Michael Thomas Flanagan's Java Scientific Library

This class contains the constructor and methods for the calculation of the gradients within 1-dimensional and 2-dimensional data arrays.
Two options are offered in the calculation of the gradients:

import directive: import flanagan.math.Gradient;

SUMMARY OF CONSTRUCTOR AND METHODS

Constructors public Gradient(double[] xx, double[] ff)
public Gradient(float[] xx, float[] ff)
public Gradient(long[] xx, long[] ff)
public Gradient(int[] xx, int[] ff)
public Gradient(double[] xx, double[] yy, double[][] ff)
public Gradient(float[] xx, float[] yy, float[][] ff)
public Gradient(long[] xx, long[] yy, long[][] ff)
public Gradient(int[] xx, int[] yy, int[][] ff)
Return Gradient Spline Interpolation 1D Array At an individual point public double splineDerivAtPoint(double xx)
At each or each sampled array element public double[] splineDeriv_1D_array()
2D Array At an individual point public double[] splineDerivAtPoint(double xx, double yy)
At each or each sampled array element public double[][] splineDeriv_2D_x_direction()
public double[][] splineDeriv_2D_y_direction()
public ArrayList<Object> splineDerivativesArray()
Numerical Differences 1D Array At an individual point public double numDerivAtPoint(double xx)
At each or each sampled array element public double[] numDeriv_1D_array()
2D Array At an individual point public double[] numDerivAtPoint(double xx, double yy)
At each or each sampled array element public double[][] numDeriv_2D_x_direction()
public double[][] numDeriv_2D_y_direction()
public ArrayList<Object> numericalDerivativesArray()
Sampling public void sampling(int samplingPeriod)
public void sampling(int xSamplingPeriod, int ySamplingPeriod)
public void sampling(int samplingPeriod, int samplingStart, int samplingEnd)
public void sampling(int xSamplingPeriod, int xSamplingStart, int xSamplingEnd, int ySamplingPeriod, int ySamplingStart, int ySamplingEnd)
Deep copy public Gradient copy()



CONSTRUCTORS
Constructors for one-dimensional arrays
public Gradient(double[] xx, double[] ff)
public Gradient(float[] xx, float[] ff)
public Gradient(long[] xx, long[] ff)
public Gradient(int[] xx, int[] ff)
Usage:                      Gradient gg = new Gradient(xx, ff);
Creates an instance of Gradient for a one-dimensional data array, f = f(x), where the x values are entered as the array xx and the f values are entered as the array ff. The two arrays must be of the same data type which maybe double, float, long or int.

Constructors for two-dimensional arrays
public Gradient(double[] xx, double[] yy, double[][] ff)
public Gradient(float[] xx, float[] yy, float[][] ff)
public Gradient(long[] xx, long[] yy, long[][] ff)
public Gradient(int[] xx, int[] yy, int[][] ff)
Usage:                      Gradient gg = new Gradient(xx, yy, ff);
Creates an instance of Gradient for a two-dimensional data array, f = f(x, y), where the x values are entered as the array xx, the y values are entered as the array yy and the f values are entered as the array ff. The three arrays must be of the same data type which maybe double, float, long or int.
The lengths of all columns in the 2D array, ff, must be equal and equal to the length of the 1D array, xx,
and the lengths of all rows in the 2D array, ff, must be equal and equal to the length of the 1D array, yy,
i.e. the dimensions of the 2D array, ff, are e.g. double[xx.length][yy.length]



METHODS

RETURN A GRADIENT OR ARRAY OF GRADIENTS
The gradients may be calculated as either
spline interpolated values or as numerical difference approximations.

Spline Interpolation Methods
The spline interpolation methods perform either a cubic spline interpolation (1D array) or a bicubic spline interpolation (2D array) on the full entered data arrays and returns the interpolated value/s of df/dx (1D array) or of ∂f/∂x and ∂f/∂y (2D array).
The classes
CubicSpline and BiCubicSplineFirstDerivative are used to calculate the interpolared first dervatives.

1D Array
At a single point in a 1D array
public double splineDerivAtPoint(double xx)
Usage:                      grad = gg.splineDerivAtPoint(xx);
This method returns the cubic spline interpolated value of the first derivative, df/dx, at the point, xx.

At each or each sampled array element in a 1D array
public double[] splineDeriv_1D_array()
Usage:                      grads = gg.splineDeriv_1D_array();
This method returns the cubic spline interpolated values of the first derivatives, df/dx, at each element or each sampled element of the entered 1D array. See
Sampling (below) for details of how to restrict the number of gradients returned. If a sampling method is not called the gradients are returned for all entered array elements.

2D Array
At a single point in a 2D array
public double[] splineDerivAtPoint(double xx, double yy)
Usage:                      grads = gg.splineDerivAtPoint(xx, yy);
This method returns the bicubic spline interpolated values of the first derivatives, ∂f/∂x and ∂f/∂y, at the point, xx, yy, as the two element array grads; grads[0] contains the value of ∂f/∂x and grads[1] contains the value of ∂f/∂y.

At each or each sampled array element in a 2D array
public double[][] splineDeriv_2D_x_direction()
Usage:                      grads = gg.splineDeriv_2D_array_x_direction();
This method returns the cubic spline interpolated values of the first derivative, ∂f/∂x, at each element or each sampled element of the entered 2D array. See
Sampling (below) for details of how to restrict the number of gradients returned. If a sampling method is not called the gradients are returned for all entered array elements.

public double[][] splineDeriv_2D_y_direction()
Usage:                      grads = gg.splineDeriv_2D_array_y_direction();
This method returns the cubic spline interpolated values of the first derivative, ∂f/∂y, at each element or each sampled element of the entered 2D array. See Sampling (below) for details of how to restrict the number of gradients returned. If a sampling method is not called the gradients are returned for all entered array elements.

public ArrayList<Object> splineDerivativesArray()
Usage:                      gradsArray = gg.splineDerivativesArray();
This method returns an ArrayLisy of two elements:

Numerical Difference Methods
The numerical difference methods calculate the value of the gradients as numerical difference approximations to the first derivatives.
1D Array
At a single point in a 1D array
public double numDerivAtPoint(double xx)
Usage:                      grad = gg.numDerivAtPoint(xx);
This method returns the numerical difference approximation of the first derivative, df/dx, at the point, xx.

At each or each sampled array element in a 1D array
public double[] numDeriv_1D_array()
Usage:                      grads = gg.numDeriv_1D_array();
This method returns the numerical difference approximations of the first derivatives, df/dx, at each element or each sampled element of the entered 1D array. See
Sampling (below) for details of how to restrict the number of gradients returned. If a sampling method is not called the gradients are returned for all entered array elements.

2D Array
At a single point in a 2D array
public double[] numDerivAtPoint(double xx, double yy)
Usage:                      grads = gg.numDerivAtPoint(xx, yy);
This method returns the numerical difference approximations of the first derivatives, ∂f/∂x and ∂f/∂y, at the point, xx, yy, as the two element array grads; grads[0] contains the value of ∂f/∂x and grads[1] contains the value of ∂f/∂y.

At each or each sampled array element in a 2D array
public double[][] numDeriv_2D_x_direction()
Usage:                      grads = gg.numDeriv_2D_array_x_direction();
This method returns the numerical difference approximation of the first derivative, ∂f/∂x, at each element or each sampled element of the entered 2D array. See
Sampling (below) for details of how to restrict the number of gradients returned. If a sampling method is not called the gradients are returned for all entered array elements.

public double[][] numDeriv_2D_y_direction()
Usage:                      grads = gg.numDeriv_2D_array_y_direction();
This method returns the numerical difference approximation of the first derivative, ∂f/∂y, at each element or each sampled element of the entered 2D array. See Sampling (below) for details of how to restrict the number of gradients returned. If a sampling method is not called the gradients are returned for all entered array elements.

public ArrayList<Object> numericalDerivativesArray()
Usage:                      gradsArray = gg.numericalDerivativesArray();
This method returns an ArrayLisy of two elements:



SAMPLING
These methods lay a mask over the entered array determining the elements within the entered array for which a gradient is returned by any of the array gradient methods.

public void sampling(int samplingPeriod)
public void sampling(int xSamplingPeriod, int ySamplingPeriod)
public void sampling(int samplingPeriod, int samplingStart, int samplingEnd)
public void sampling(int xSamplingPeriod, int xSamplingStart, int xSamplingEnd, int ySamplingPeriod, int ySamplingStart, int ySamplingEnd)
Usage:                      gg.sampling(samplingPeriod);
On calling this method gradients will be returned, by any of the array gradient methods, at points determined by the sampling period, msamplingPeriod, as indicated in the following examples.
NB: indices start at 0.

Usage:                      gg.sampling(xSamplingPeriod, ySamplingPeriod);
On calling this method gradients will be returned, by any of the array gradient methods, at points determined by the sampling periods, xSamplingPeriod and ySamplingPeriod, as indicated in the following example.
NB: indices start at 0.

Usage:                      gg.sampling(samplingPeriod, samplingStart, samplingEnd);
On calling this method gradients will be returned, by any of the array gradient methods, at points determined by the sampling periods, samplingPeriod, as indicated in the following examples. No gradients are returned for points below the index, samplingStart, and above the index, samplingEnd.
NB: indices start at 0.

Usage:                      gg.sampling(xSamplingPeriod, xSamplingStart, xSamplingEnd, ySamplingPeriod, ySamplingStart, ySamplingEnd);
On calling this method gradients will be returned, by any of the array gradient methods, at points determined by the sampling periods, xSamplingPeriod and ySamplingPeriod, as indicated in the following example. No gradients are returned for points below the indices, xSamplingStart and ySamplingStart, and above the indices, xSamplingEnd and ySamplingEnd.
NB: indices start at 0.



DEEP COPY
public Gradient copy()
Usage:                      copy = gg.copy();
This method returns a deep copy of gg.


OTHER CLASSES USED BY THIS CLASS

This class uses the following classes in this library:



This page was prepared by Dr Michael Thomas Flanagan