Define some essential mathematical functions.
Numerical Integrations
ACTest.trapz — Functiontrapz(x::AbstractMesh, y::AbstractVector{T}) where {T<:N64}Perform numerical integration by using the composite trapezoidal rule.
Arguments
- x -> Real frequency mesh.
- y -> Function values at real axis.
Returns
- ℐ -> The final value.
See also: simpson.
trapz(
x::AbstractVector{S},
y::AbstractVector{T},
linear::Bool = false
) where {S<:Number, T<:Number}Perform numerical integration by using the composite trapezoidal rule. Note that it supports arbitrary precision via BigFloat.
Arguments
- x -> Real frequency mesh.
- y -> Function values at real axis.
- linear -> Whether the given mesh is linear?
Returns
- ℐ -> The final value.
See also: simpson.
ACTest.simpson — Functionsimpson(
x::AbstractVector{S},
y::AbstractVector{T}
) where {S<:Number, T<:Number}Perform numerical integration by using the simpson rule. Note that the length of x and y must be odd numbers. And x must be a linear and uniform mesh.
Arguments
- x -> Real frequency mesh.
- y -> Function values at real axis.
Returns
- ℐ -> The final value.
See also: trapz.
Einstein Summation Convention
ACTest.@einsum — Macro@einsum(ex)Perform Einstein summation like operations on Julia Arrays.
Examples
Basic matrix multiplication can be implemented as:
@einsum A[i, j] := B[i, k] * C[k, j]If the destination array is preallocated, then use =:
A = ones(5, 6, 7) # Preallocated space
X = randn(5, 2)
Y = randn(6, 2)
Z = randn(7, 2)
# Store the result in A, overwriting as necessary:
@einsum A[i, j, k] = X[i, r] * Y[j, r] * Z[k, r]If destination is not preallocated, then use := to automatically create a new array for the result:
X = randn(5, 2)
Y = randn(6, 2)
Z = randn(7, 2)
# Create new array B with appropriate dimensions:
@einsum B[i, j, k] := X[i, r] * Y[j, r] * Z[k, r]