Home Login  |   Contact  |   About Us       Tuesday, May 17, 2022   

j0185201- Back to Home
   Skip Navigation LinksHOME ›  AREAS OF EXPERTISE ›   Numerical Difference ›  ~ Backward Difference



Skip Navigation Links.



"Numerical Differentiation"
Backward Difference Method

       Derivatives for f(x) = sin(x)


Y-Array =

       Derivatives for Y Array values:




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[10];
           // 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);
                     listBox1.Items.Add("f'(x) = " + dy.ToString());
                     dy = Differentiation.Backward2(f, 7, h);
                     listBox1.Items.Add("f''(x) = " + dy.ToString());
                     dy = Differentiation.Backward3(f, 7, h);
                     listBox1.Items.Add("f'''(x) = " + dy.ToString());
                     dy = Differentiation.Backward4(f, 7, h);
                     listBox1.Items.Add("f''''(x) = " + dy.ToString());
           // Calculate derivatives for array values:
                 foreach (double y1 in yarray)
                     listBox2.Items.Add(" " + y1.ToString());
                     dy = Differentiation.Backward1(yarray, 7, h);
                     listBox3.Items.Add("y' = " + dy.ToString());
                     dy = Differentiation.Backward2(yarray, 7, h);
                     listBox3.Items.Add("y'' = " + dy.ToString());
                     dy = Differentiation.Backward3(yarray, 7, h);
                     listBox3.Items.Add("y''' = " + dy.ToString());
                     dy = Differentiation.Backward4(yarray, 7, h);
                     listBox3.Items.Add("y'''' = " + dy.ToString());
              }
           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


Consulting Services - Back to Home
Home

Home Math, Analysis,
  expertise..."

EIGENVALUE
SOLUTIONS...


> Rayleigh-Quotient Method

> Cubic Spline Method

 

Applied Mathematical Algorithms

Home

ComplexFunctions

Home

NonLinear
Home

Differentiation
Home

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
Understanding
Mining


MiningMastery
MineralNews
MineralCommodities
MineralForum
Crystallography
Services


NumericalModeling
WebServices
MainframeServices
OutsourceServices

LINKED IN
KMP ARTICLES
Brand





Home

Login

Contact
Since 2006 All Rights Reserved  © KMP Software Engineering LINKS | PRIVACY POLICY | LEGAL NOTICE