Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs to linear problem #128

Merged
merged 2 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
'show-inheritance': True
}

mathjax3_config = {
'tex': {
'macros': {
'diag': ['\\operatorname{diag}']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh very nice that we can add macros!

}
}
}

myst_heading_anchors = 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes an unrelated warning from the contributing guide markdown


bibtex_bibfiles = ['references.bib']

html_theme = 'sphinx_rtd_theme'
Expand Down
21 changes: 20 additions & 1 deletion toolbox/+otp/+linear/+presets/Alpha.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
classdef Alpha < otp.linear.LinearProblem
%ALPHA
% A diagonal linear preset with eigenvalues logarithmically spaced between distances $r_{min}$ and $r_{max}$ from
% the origin at an angle $α$ measured in degrees clockwise from the negative real axis. It can be used to check for
% $A(α)$ stability of a time integration scheme. This preset uses $t ∈ [0, 1]$, $y_0 = [1, 1, …, 1]^T$, and
%
% $$
% Λ_1 &= \diag(-r_1 e^{-i π α / 180}, -r_2 e^{-i π α / 180}, …, -r_N e^{-i π α / 180}), \\
% r_j &= r_{min}^{\frac{N - j}{N - 1}} r_{max}^{\frac{j - 1}{N - 1}}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do \max and \min ? that might make it look better

% $$

methods
function obj = Alpha(varargin)
% Create the alpha linear problem object.
%
% Parameters
% ----------
% varargin
% A variable number of name-value pairs. The accepted names are
%
% - ``Alpha`` – The angle $α$ measured in degrees clockwise from the negative real axis.
% - ``N`` – The number of eigenvalues $N$.
% - ``Range`` – The range $[r_{min}, r_{max}]$ of the eigenvalues.
% - ``Sparse`` – If true, the matrix will be in sparse format. Otherwise, it will be dense.

p = inputParser();
p.addParameter('Alpha', 0);
p.addParameter('N', 10);
Expand Down
11 changes: 11 additions & 0 deletions toolbox/+otp/+linear/+presets/Canonical.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
classdef Canonical < otp.linear.LinearProblem
% A scalar linear preset with $t ∈ [0, 1]$, $y_0 = 1$, and $Λ_1 = -1$.

methods
function obj = Canonical(varargin)
% Create the canonical linear problem object.
%
% Parameters
% ----------
% varargin
% A variable number of name-value pairs. The accepted names are
%
% - ``Lambda`` – Cell array of matrices for each partition $Λ_i y$.

params = otp.linear.LinearParameters('Lambda', {-1}, varargin{:});
tspan = [0, 1];
y0 = ones(size(params.Lambda{1}, 1), 1);
Expand Down
2 changes: 1 addition & 1 deletion toolbox/+otp/+linear/LinearParameters.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
% Parameters for the linear problem.

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

Expand Down
44 changes: 43 additions & 1 deletion toolbox/+otp/+linear/LinearProblem.m
Original file line number Diff line number Diff line change
@@ -1,14 +1,56 @@
classdef LinearProblem < otp.Problem
% A linear, constant coefficient, homogeneous ODE which supports a partitioned right-hand side.
%
% The linear problem is given by
%
% $$
% y' = \sum_{i=1}^{p} Λ_i y,
% $$
%
% where $p$ is the number of partitions and $Λ_i ∈ ℂ^{N × N}$ for $i = 1, …, p$.
%
% This is often used to assess the stability of time integration methods, with the case of $p = N = 1$ referred to
% as the Dahlquist test problem.
%
% Notes
% -----
% +---------------------+----------------------------------------------------------------+
% | Type | ODE |
% +---------------------+----------------------------------------------------------------+
% | Number of Variables | arbitrary |
% +---------------------+----------------------------------------------------------------+
% | Stiff | possibly, depending on the eigenvalues of $\sum_{i=1}^{p} Λ_i$ |
% +---------------------+----------------------------------------------------------------+
%
% Example
% -------
% >>> problem = otp.linear.presets.Canonical('Lambda', {-1, -2, -3});
% >>> problem.RHSPartitions{2}.JacobianMatrix
% ans = -2

properties (SetAccess = private)
RHSPartitions
% A cell array of $p$ right-hand sides for each partition $Λ_i y$.
RHSPartitions
end

properties (Dependent)
% The number of partitions $p$.
NumPartitions
end

methods
function obj = LinearProblem(timeSpan, y0, parameters)
% Create a linear problem object.
%
% Parameters
% ----------
% timeSpan : numeric(1, 2)
% The start and final time.
% y0 : numeric(:, 1)
% The initial conditions.
% parameters : LinearParameters
% The parameters.

[email protected]('Linear', [], timeSpan, y0, parameters);
end

Expand Down