philsupertramp/game-math
Loading...
Searching...
No Matches
Functions
Differentiation.h File Reference
#include "../../Matrix.h"
#include "../../matrix_utils.h"
#include "../utils.h"

Go to the source code of this file.

Functions

Matrix< double > forwardDiff (const Matrix< double > &x, const Matrix< double > &y)
 
Matrix< double > backwardDiff (const Matrix< double > &x, const Matrix< double > &y)
 
Matrix< double > centralDiff (const Matrix< double > &x, const Matrix< double > &y)
 
Matrix< double > backwardDiff2 (const Matrix< double > &x, const Matrix< double > &y)
 
Matrix< double > centralDiff4 (const Matrix< double > &x, const Matrix< double > &y)
 

Detailed Description

Numerical differentiation methods to approximate the first order derivative using support values.

$$f'(x) = ?$$

Implemented quotients:

Usage:

// create a function
auto fun = [](const Matrix<double>& input){ return input.Apply([](const double& val){ return val*val; });};
// create support values
auto xk = linspace(-5, 5, 20).Transpose();
// calculate 1st derivative
centralDiff(xk, fun(xk));
Matrix< double > centralDiff(const Matrix< double > &x, const Matrix< double > &y)
Definition: Differentiation.h:92
Definition: Matrix.h:42
constexpr Matrix< T > Transpose() const
Definition: Matrix.h:256
Matrix< double > linspace(double start, double end, unsigned long num_elements)

Function Documentation

◆ backwardDiff()

Matrix< double > backwardDiff ( const Matrix< double > &  x,
const Matrix< double > &  y 
)
inline

Computes backward difference quotient $$ f'(x) = \frac{f(x)-f(x-h)}{h} $$ Error O(dx)

Parameters
xx-values
yy-values @returnss approximated first differential evaluated on x-values
Examples
numerics/analysis/TestDifferentiation.cpp.

◆ backwardDiff2()

Matrix< double > backwardDiff2 ( const Matrix< double > &  x,
const Matrix< double > &  y 
)
inline

Computes backward difference quotient for 1st differential uses 2nd order polynomial for approximation

Error O(dx)

Parameters
xx-values
yy-values @returnss approximated second differential evaluated on x-values
Examples
numerics/analysis/TestDifferentiation.cpp.

◆ centralDiff()

Matrix< double > centralDiff ( const Matrix< double > &  x,
const Matrix< double > &  y 
)
inline

Computes central difference quotient $$ f'(x) = \frac{f(x+h)-f(x-h)}{2h} $$ Error O(dx^2)

Parameters
xx-values
yy-values @returnss approximated first differential evaluated on x-values
Examples
numerics/analysis/TestDifferentiation.cpp.

◆ centralDiff4()

Matrix< double > centralDiff4 ( const Matrix< double > &  x,
const Matrix< double > &  y 
)
inline

Computes central difference quotient for 1st differential uses 2nd order polynomial for approximation

Error O(dx^2)

Parameters
xx-values
yy-values @returnss approximated second differential evaluated on x-values
Examples
numerics/analysis/TestDifferentiation.cpp.

◆ forwardDiff()

Matrix< double > forwardDiff ( const Matrix< double > &  x,
const Matrix< double > &  y 
)
inline

Computes forward difference quotient $$ \frac{f(x+h)-f(x)}{h} $$ Error O(dx)

Parameters
xx-values
yy-values @returnss approximated differential evaluated on x-values
Examples
numerics/analysis/TestDifferentiation.cpp.