Skip to content

Commit 90d4c58

Browse files
Add docs to linear problem (#128)
1 parent ed63ab5 commit 90d4c58

File tree

5 files changed

+85
-3
lines changed

5 files changed

+85
-3
lines changed

docs/conf.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
'show-inheritance': True
3333
}
3434

35+
mathjax3_config = {
36+
'tex': {
37+
'macros': {
38+
'diag': ['\\operatorname{diag}']
39+
}
40+
}
41+
}
42+
43+
myst_heading_anchors = 2
44+
3545
bibtex_bibfiles = ['references.bib']
3646

3747
html_theme = 'sphinx_rtd_theme'

toolbox/+otp/+linear/+presets/Alpha.m

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
classdef Alpha < otp.linear.LinearProblem
2-
%ALPHA
2+
% A diagonal linear preset with eigenvalues logarithmically spaced between distances $r_{min}$ and $r_{max}$ from
3+
% the origin at an angle $α$ measured in degrees clockwise from the negative real axis. It can be used to check for
4+
% $A(α)$ stability of a time integration scheme. This preset uses $t ∈ [0, 1]$, $y_0 = [1, 1, …, 1]^T$, and
35
%
6+
% $$
7+
% Λ_1 &= \diag(-r_1 e^{-i π α / 180}, -r_2 e^{-i π α / 180}, …, -r_N e^{-i π α / 180}), \\
8+
% r_j &= r_{min}^{\frac{N - j}{N - 1}} r_{max}^{\frac{j - 1}{N - 1}}.
9+
% $$
10+
411
methods
512
function obj = Alpha(varargin)
13+
% Create the alpha linear problem object.
14+
%
15+
% Parameters
16+
% ----------
17+
% varargin
18+
% A variable number of name-value pairs. The accepted names are
19+
%
20+
% - ``Alpha`` – The angle $α$ measured in degrees clockwise from the negative real axis.
21+
% - ``N`` – The number of eigenvalues $N$.
22+
% - ``Range`` – The range $[r_{min}, r_{max}]$ of the eigenvalues.
23+
% - ``Sparse`` – If true, the matrix will be in sparse format. Otherwise, it will be dense.
24+
625
p = inputParser();
726
p.addParameter('Alpha', 0);
827
p.addParameter('N', 10);

toolbox/+otp/+linear/+presets/Canonical.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
classdef Canonical < otp.linear.LinearProblem
2+
% A scalar linear preset with $t ∈ [0, 1]$, $y_0 = 1$, and $Λ_1 = -1$.
3+
24
methods
35
function obj = Canonical(varargin)
6+
% Create the canonical linear problem object.
7+
%
8+
% Parameters
9+
% ----------
10+
% varargin
11+
% A variable number of name-value pairs. The accepted names are
12+
%
13+
% - ``Lambda`` – Cell array of matrices for each partition $Λ_i y$.
14+
415
params = otp.linear.LinearParameters('Lambda', {-1}, varargin{:});
516
tspan = [0, 1];
617
y0 = ones(size(params.Lambda{1}, 1), 1);

toolbox/+otp/+linear/LinearParameters.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
% Parameters for the linear problem.
33

44
properties
5-
%LAMBDA is a cell array of same size inputs
5+
% A cell array of matrices for each partition $Λ_i y$.
66
Lambda %MATLAB ONLY: {mustBeNonempty, otp.utils.validation.mustBeNumericalCell} = {-1}
77
end
88

toolbox/+otp/+linear/LinearProblem.m

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,56 @@
11
classdef LinearProblem < otp.Problem
2+
% A linear, constant coefficient, homogeneous ODE which supports a partitioned right-hand side.
3+
%
4+
% The linear problem is given by
5+
%
6+
% $$
7+
% y' = \sum_{i=1}^{p} Λ_i y,
8+
% $$
9+
%
10+
% where $p$ is the number of partitions and $Λ_i ∈ ℂ^{N × N}$ for $i = 1, …, p$.
11+
%
12+
% This is often used to assess the stability of time integration methods, with the case of $p = N = 1$ referred to
13+
% as the Dahlquist test problem.
14+
%
15+
% Notes
16+
% -----
17+
% +---------------------+----------------------------------------------------------------+
18+
% | Type | ODE |
19+
% +---------------------+----------------------------------------------------------------+
20+
% | Number of Variables | arbitrary |
21+
% +---------------------+----------------------------------------------------------------+
22+
% | Stiff | possibly, depending on the eigenvalues of $\sum_{i=1}^{p} Λ_i$ |
23+
% +---------------------+----------------------------------------------------------------+
24+
%
25+
% Example
26+
% -------
27+
% >>> problem = otp.linear.presets.Canonical('Lambda', {-1, -2, -3});
28+
% >>> problem.RHSPartitions{2}.JacobianMatrix
29+
% ans = -2
30+
231
properties (SetAccess = private)
3-
RHSPartitions
32+
% A cell array of $p$ right-hand sides for each partition $Λ_i y$.
33+
RHSPartitions
434
end
535

636
properties (Dependent)
37+
% The number of partitions $p$.
738
NumPartitions
839
end
940

1041
methods
1142
function obj = LinearProblem(timeSpan, y0, parameters)
43+
% Create a linear problem object.
44+
%
45+
% Parameters
46+
% ----------
47+
% timeSpan : numeric(1, 2)
48+
% The start and final time.
49+
% y0 : numeric(:, 1)
50+
% The initial conditions.
51+
% parameters : LinearParameters
52+
% The parameters.
53+
1254
obj@otp.Problem('Linear', [], timeSpan, y0, parameters);
1355
end
1456

0 commit comments

Comments
 (0)