 Login  |   Contact  |   About Us       Tuesday, May 17, 2022  ~ Forward Difference ~ Backward Difference ~ Richardson Extrap

 "Numerical Differentiation" Backward Difference Method

Derivatives for f(x) = sin(x)

 f'(x) = 1.06484875714447 f''(x) = -0.367843914912418 f'''(x) = -1.84058783612506 f''''(x) = -1.15226924790282

 Y-Array = 0 0.841470984807897 0.909297426825682 0.141120008059867 -0.756802495307928 -0.958924274663138 -0.279415498198926 0.656986598718789 0.989358246623382 0.412118485241757 -0.54402111088937 -0.999990206550703 -0.536572918000435 0.420167036826641 0.99060735569487

Derivatives for Y Array values:

 y' = 1.06484875714447 y'' = -0.367843914912418 y''' = -1.84058783612506 y'''' = -1.15226924790282

 Specify New Y Array size: Specify New delegate x values = { , } [ Initial delegate function: x = {7) ] (s/b within y-array size) [ Initial Y index: {7} ] (selected delegate function: x values will match Y index values) [ Initial Y Array: {15} ]

IMPLEMENTATION
Backward Difference Method

The backward finite difference can be obtained from the equation shown under "Overview - Numerical Differentiation" tab. The first four derivatives of the function f(x) are given by the following formulas:

 f'(x) = f(x + h) - f(x)                  h f''(x) = f(x + 2h) - 2f(x + h) + f(x)                       h2 f'''(x) = f(x + 3h) - 3f(x + 2h) + 3(f + h) - f(x)                             h3 f(4)(x) = f(x + 4h) - 4f(x + 3h) + 6f(x + 2h) - 4f(x + h) + f(x)                                     h4

The above equations are usually not used to compute derivatives because they have a large truncation error (order of O(h)). The common practice is to use expressions of O(h2). To obtain backward difference formulas of this order, it is necessary to retain more terms in the Taylor series. Below are listed the results (without derivations):

 f'(x) = -3f(x) + 4f(x + h) - f(x + 2h)                      2h f''(x) = 2f(x) - 5f(x + h) + 4f(x + 2h) - f(x +3h)                              h2 f'''(x) = -5f(x) + 18f(x + h) - 24f(x + 2h) + 14f(x +3h) - 3f(x +4h)                                       2h3 f(4)(x) = 3f(x) - 14f(x + h) + 26f(x + 2h) - 24f(x +3h) + 11f(x +4h) - 2f(x + 5h)                                                   h4

Each derivative has two overloaded methods: one for the function and another for the array of data values. In order to calculate derivatives for a function, one has to pass a delegate function f(x), the value of x at which the derivative is computed, and the increment h as input parameters.

On the other hand, in order to calculate derivatives for an array of data values, each method has input parameters which pass the yarray values, the index called yindex which specifies the location at which the derivative is computed, and the increment h. Here, the increment parameter is the value used to generate the function values.

The x increment defined as h = 1 and created the Y array of the sine function using this increment. Then calculated the first four derivatives directly for the delegate function at x = 7. Derivatives for Y array also at x = 7, which corresponds to yindex = 7.

Running this example generates the results above. The reader will see that derivatives for the function and for the array values, as expected, are almost identical. Slight differences only because numerical round-off error. Users can manipulate function and array values.   Testing the Backward Difference Method

To test the Backward Difference method, a new static method has been added to show how to calculate the first four derivatives for f(x) = Sin x. The TestBackwardMethod() method has been written, added and executed:

static void TestBackwardMethod();
{
double h = 0.1;
double[] yarray=new double;
// create yarray:
for (int i = 0; i < 10; i++)
yarray[i] = f(i * h);
// Calculate derivatives for function:
double dy = Differentiation.Backward(f, 7, h);
dy = Differentiation.Backward2(f, 7, h);
dy = Differentiation.Backward3(f, 7, h);
dy = Differentiation.Backward4(f, 7, h);
// Calculate derivatives for array values:
foreach (double y1 in yarray)
dy = Differentiation.Backward1(yarray, 7, h);
dy = Differentiation.Backward2(yarray, 7, h);
dy = Differentiation.Backward3(yarray, 7, h);
dy = Differentiation.Backward4(yarray, 7, h);
}
static double f(double x)
{
return Math.Sin(x);
}

 Other Implementations...

 Object-Oriented Implementation Graphics and Animation Sample Applications Ore Extraction Optimization Vectors and Matrices Complex Numbers and Functions Ordinary Differential Equations - Euler Method Ordinary Differential Equations 2nd-Order Runge-Kutta Ordinary Differential Equations 4th-Order Runge-Kutta Higher Order Differential Equations Nonlinear Systems Numerical Integration Numerical Differentiation Function Evaluation  Math, Analysis,
expertise..."

EIGENVALUE
SOLUTIONS...

> Rayleigh-Quotient Method

> Cubic Spline Method

 Applied Mathematical Algorithms ComplexFunctions NonLinear Differentiation Integration
 About Us KMP Software Engineering is an independent multidisciplinary engineering consulting company specializing in mathematical algorithms. Areas of Expertise SpecialFunctions VectorsMatrices OptimizationMethods ComplexNumbers Interpolation CurveFitting NonLinearSystems LinearEquations DistributionFunctions NumericalDifferentiation NumericalIntegration DifferentialEquations Smalltalk FiniteBoundary Eigenvalue Graphics UnderstandingMining MiningMastery MineralNews MineralCommodities MineralForum Crystallography Services NumericalModeling WebServices MainframeServices OutsourceServices LINKED IN KMP ARTICLES Brand Login Contact