Learn R Programming

comphy (version 1.0.5)

forwdif: Forward differences

Description

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

Usage

forwdif(f)

Value

An upper triangular matrix with \(n+1\) rows and \(n+1\) columns. The first column includes the tabulated values of the function. The second column includes the \(n\)

forward differences of first order and a zero. The third column includes the \(n-1\) forward differences of second order and two zeros. And so on.

Arguments

f

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

Details

The forward difference of first order is $$ f(x_i+h)-f(x_i) $$ Forward differences of higher orders follow from this one, where the function \(f\) is replaced by the forward difference of previous order. All values are contained in a \((n+1)\times(n+1)\) upper 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 forward differences
F <- forwdif(f)
print(F)

Run the code above in your browser using DataLab