Learn R Programming

comphy (version 1.0.5)

backdif: Backward differences

Description

Computes backward differences of all orders up to n, based on n+1 tabulated points on a regular grid.

Usage

backdif(f)

Value

A lower triangular matrix with \(n+1\) rows and \(n+1\) columns. The first column includes the tabulated values of the function. The second column includes a zero and the \(n\) backward differences of first order. The third column includes two zeros and the \(n-1\) forward differences of second order. And so on.

Arguments

f

A vector of real numbers. Tabulated (known) values of the function, corresponding to a regular grid.

Details

The backward difference of first order is $$ f(x_i)-f(x_i-h) $$ Backward differences of higher orders follow from this one, where the function \(f\) is replaced by the backward difference of previous order. All values are contained in a \((n+1)\times(n+1)\) lower triangular matrix.

Examples

Run this code
# Tabulated values: f(x) = x^3+x^2-x-1
x <- c(0,1,2,3)
f <- x^3+x^2-x-1

# Triangular matrix with backward differences
B <- backdif(f)
print(B)

Run the code above in your browser using DataLab