View Source Scholar.Integrate (Scholar v0.4.0)
Module for numerical integration.
Summary
Functions
Integrate y along the given axis using the simpson's rule.
The integration happens in sequence along elements of x.
Integrate y along the given axis using the composite trapezoidal rule.
Integrate y along the given axis using the composite trapezoidal rule.
The integration happens in sequence along elements of x.
Integrate y along the given axis using the composite trapezoidal rule.
Functions
Integrate y along the given axis using the simpson's rule.
The integration happens in sequence along elements of x.
Options
:axis- Axis along which to integrate. The default value is-1.:keep_axis(boolean/0) - If set to true, the axis which is reduced is kept. The default value isfalse.:even- If set to:avg, the average of the first and last interval is used in the integration. If set to:first, the first interval is used in the integration. If set to:last, the last interval is used in the integration. The default value is:avg.
Examples
iex> y = Nx.tensor([1, 2, 3])
iex> x = Nx.tensor([4, 5, 6])
iex> Scholar.Integrate.simpson(y, x)
#Nx.Tensor<
f32
4.0
>
iex> y = Nx.tensor([[0, 1, 2], [3, 4, 5]])
iex> x = Nx.tensor([[1, 2, 3], [1, 2, 3]])
iex> Scholar.Integrate.simpson(y, x)
#Nx.Tensor<
f32[2]
[2.0, 8.0]
>
iex> y = Nx.tensor([[0, 1, 2], [3, 4, 5]])
iex> x = Nx.tensor([[1, 1, 1], [2, 2, 2]])
iex> Scholar.Integrate.simpson(y, x, axis: 0)
#Nx.Tensor<
f32[3]
[1.5, 2.5, 3.5]
>
Integrate y along the given axis using the composite trapezoidal rule.
This is a simplified version of trapezoidal/3 that assumes x is
a uniform tensor along axis with step size equal to dx.
Options
:axis- Axis along which to integrate. The default value is-1.:keep_axis(boolean/0) - If set to true, the axis which is reduced is kept. The default value isfalse.:even- If set to:avg, the average of the first and last interval is used in the integration. If set to:first, the first interval is used in the integration. If set to:last, the last interval is used in the integration. The default value is:avg.:dx- The spacing between samples. The default value is1.0.
Examples
iex> y = Nx.tensor([1, 2, 3])
iex> Scholar.Integrate.simpson_uniform(y)
#Nx.Tensor<
f32
4.0
>
iex> y = Nx.tensor([1, 2, 3])
iex> Scholar.Integrate.simpson_uniform(y, dx: 2)
#Nx.Tensor<
f32
8.0
>
iex> y = Nx.tensor([[0, 1, 2], [3, 4, 5]])
iex> Scholar.Integrate.simpson_uniform(y, dx: 2, axis: 0)
#Nx.Tensor<
f32[3]
[3.0, 5.0, 7.0]
>
Integrate y along the given axis using the composite trapezoidal rule.
The integration happens in sequence along elements of x.
Options
:axis- Axis along which to integrate. The default value is-1.:keep_axis(boolean/0) - If set to true, the axis which is reduced is kept. The default value isfalse.
Examples
iex> y = Nx.tensor([1, 2, 3])
iex> x = Nx.tensor([4, 5, 6])
iex> Scholar.Integrate.trapezoidal(y, x)
#Nx.Tensor<
f32
4.0
>
iex> y = Nx.tensor([[0, 1, 2], [3, 4, 5]])
iex> x = Nx.tensor([[1, 2, 3], [1, 2, 3]])
iex> Scholar.Integrate.trapezoidal(y, x)
#Nx.Tensor<
f32[2]
[2.0, 8.0]
>
iex> y = Nx.tensor([[0, 1, 2], [3, 4, 5]])
iex> x = Nx.tensor([[1, 1, 1], [2, 2, 2]])
iex> Scholar.Integrate.trapezoidal(y, x, axis: 0)
#Nx.Tensor<
f32[3]
[1.5, 2.5, 3.5]
>
Integrate y along the given axis using the composite trapezoidal rule.
This is a simplified version of trapezoidal/3 that assumes x is
a uniform tensor along axis with step size equal to dx.
Options
:axis- Axis along which to integrate. The default value is-1.:keep_axis(boolean/0) - If set to true, the axis which is reduced is kept. The default value isfalse.:dx- The spacing between samples. The default value is1.0.
Examples
iex> y = Nx.tensor([1, 2, 3])
iex> Scholar.Integrate.trapezoidal_uniform(y)
#Nx.Tensor<
f32
4.0
>
iex> y = Nx.tensor([1, 2, 3])
iex> Scholar.Integrate.trapezoidal_uniform(y, dx: 2)
#Nx.Tensor<
f32
8.0
>
iex> y = Nx.tensor([[0, 1, 2], [3, 4, 5]])
iex> Scholar.Integrate.trapezoidal_uniform(y, dx: 2, axis: 0)
#Nx.Tensor<
f32[3]
[3.0, 5.0, 7.0]
>