calculus_m Module

This module defines some functions that perform common calculus operations, including differentiating, integrating, and interpolating discretized data.


Uses


Functions

public pure function mean_array_re(x) result(r)

Calculates the mean value of a real-valued array.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: x

Real-valued array

Return Value real(kind=wp)

Mean value

public pure function mean_array_cx(x) result(r)

Calculates the mean value of a complex-valued array.

Arguments

Type IntentOptional Attributes Name
complex(kind=wp), intent(in), dimension(:) :: x

Complex-valued array

Return Value complex(kind=wp)

Mean value

public pure function differentiate_array_re(x, y) result(r)

Calculates the numerical derivative of an array y wrt. x using central differences at the interior points and forward/backward differences at the exterior points. All three approaches yield two-point approximations of the derivatives, thus the mesh spacing does not have to be uniform.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: x

Variable x

real(kind=wp), intent(in), dimension(size(x)) :: y

Function y(x)

Return Value real(kind=wp), dimension(size(x))

Derivative dy/dx

public pure function differentiate_array_cx(x, y) result(r)

Complex version of differentiate_array_re.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: x

Variable x

complex(kind=wp), intent(in), dimension(size(x)) :: y

Function y(x)

Return Value complex(kind=wp), dimension(size(x))

Derivative dy/dx

public pure function integrate_array_re(x, y) result(r)

Calculates the integral of an array y wrt. x using the trapezoid method. The mesh spacing does not necessarily have to be uniform.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: x

Variable x

real(kind=wp), intent(in), dimension(size(x)) :: y

Function y(x)

Return Value real(kind=wp)

Integral ∫y(x)·dx

public pure function integrate_array_cx(x, y) result(r)

Complex version of integrate_array_re.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: x

Variable x

complex(kind=wp), intent(in), dimension(size(x)) :: y

Function y(x)

Return Value complex(kind=wp)

Integral ∫y(x)·dx

public function integrate_range_re(x, y, a, b) result(r)

Constructs a piecewise hermitian cubic interpolation of an array y(x) from discrete numerical data, and then integrates the interpolation in the range (a, b). The mesh spacing does not have to be uniform.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: x

Variable x

real(kind=wp), intent(in), dimension(size(x)) :: y

Function y(x)

real(kind=wp), intent(in) :: a

Left endpoint

real(kind=wp), intent(in) :: b

Right endpoint

Return Value real(kind=wp)

Integral ∫y(x)·dx

public function integrate_range_cx(x, y, a, b) result(r)

Complex version of integrate_range_re.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: x

Variable x

complex(kind=wp), intent(in), dimension(size(x)) :: y

Function y(x)

real(kind=wp), intent(in) :: a

Left endpoint

real(kind=wp), intent(in) :: b

Right endpoint

Return Value complex(kind=wp)

Integral ∫y(x)·dx

public function interpolate_array_re(x, y, p) result(r)

Constructs a piecewise hermitian cubic interpolation of an array y(x) based on discrete numerical data and evaluates the interpolation at p. Note that the mesh spacing does not necessarily have to be uniform.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: x

Variable x

real(kind=wp), intent(in), dimension(size(x)) :: y

Function y(x)

real(kind=wp), intent(in), dimension(:) :: p

Point array p

Return Value real(kind=wp), dimension(size(p))

Interpolation y(p)

public function interpolate_array_cx(x, y, p) result(r)

Complex version of interpolate_array_re.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: x

Variable x

complex(kind=wp), intent(in), dimension(size(x)) :: y

Function y(x)

real(kind=wp), intent(in), dimension(:) :: p

Point array p

Return Value complex(kind=wp), dimension(size(p))

Interpolation y(p)

public function interpolate_point_re(x, y, p) result(r)

Wrapper for interpolate_array_re that accepts scalar arguments.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: x

Variable x

real(kind=wp), intent(in), dimension(size(x)) :: y

Function y(x)

real(kind=wp), intent(in) :: p

Single point p

Return Value real(kind=wp)

Interpolation y(p)

public function interpolate_point_cx(x, y, p) result(r)

Complex version of interpolate_point_re.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: x

Variable x

complex(kind=wp), intent(in), dimension(size(x)) :: y

Function y(x)

real(kind=wp), intent(in) :: p

Single point p

Return Value complex(kind=wp)

Interpolation y(p)

public pure function interpolate_point_matrix_re(x, y, p) result(r)

Interpolates a matrix function using Catmull-Rom splines.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: x

Variable x

real(kind=wp), intent(in), dimension(:, :, :) :: y

Function y(x)

real(kind=wp), intent(in) :: p

Single point p

Return Value real(kind=wp), dimension(size(y, 1), size(y, 2))

Interpolation y(p)


Subroutines

public pure subroutine linspace_array_re(array, first, last)

Populates an array with elements from first to last, inclusive.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(out), dimension(:) :: array

Output array to populate

real(kind=wp), intent(in) :: first

Value of first element

real(kind=wp), intent(in) :: last

Value of last element