-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.m
More file actions
58 lines (32 loc) · 1.42 KB
/
utils.m
File metadata and controls
58 lines (32 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
BeginPackage["Utils`"];
Unprotect @@ Names["Utils`*"];
ClearAll @@ Names["Utils`*"];
SquareMatrixQ::usage = "gives True if expr is a list of lists or a
two-dimensional SparseArray object that can represent a matrix whose two
dimensions are of the same order, and gives false otherwise";
MarkovMatrixQ::usage = "gives True if expr is a square matrix and the sum
of each row equals 1, and gives false otherwise";
NonSingularMatrixQ::usage = "gives True is the expr is a list of lists or a
two-dimensional SparseArray object that can represent a matrix whose determinant
is non-zero";
J::usage = "Compute the Jacobian of a system n equations by n variables";
SpectralBound::usage = "Compute the spectral bound of a square matrix (i.e.
maximum real part of all eigenvalues)";
SpectralRadius::usage = "Compute the spectral radius of a square matrix (i.e.
the maximum absolute value of all eigenvalues)"
Begin["`Private`"]
SquareMatrixQ[expr_] :=
MatrixQ[expr] && Length[Union[Dimensions[expr]]] == 1;
MarkovMatrixQ[expr_] :=
SquareMatrixQ[expr] && MatchQ[Total /@ expr, {(1 | 1.) ..}];
NonSingularMatrixQ[expr_] :=
MatrixQ[expr] && Det[expr] != 0;
J[eqs_?ListQ, vars_?ListQ] :=
Outer[D, eqs, vars] /; Length[eqs] == Length[vars];
SpectralBound[mat_?SquareMatrixQ] :=
Max[Re[Eigenvalues[mat]]];
SpectralRadius[mat_?SquareMatrixQ] :=
Max[Abs[Eigenvalues[mat]]];
End[ ]
Protect @@ Names["Utils`*"];
EndPackage[ ];