Skip to content

Commit

Permalink
Features:
Browse files Browse the repository at this point in the history
	- Bartels-Stewart Algorithm Diagnostics #1 (63, 64)
	- Bartels-Stewart Algorithm Diagnostics #2 (65, 66)
	- Sylvester Equation Solution Annotated Shell (67, 68, 69)


Bug Fixes/Re-organization:

	- Numerical Analyzer Bartels-Stewart Algorithm (62)


Samples:

	- QR Decomposition Matrix Util (63, 64)
	- Graham Schmidt Matrix Orthonormalization Process (70, 71, 72)
	- Bartels-Stewart Algorithm Run #1 (73, 74, 75)
	- Bartels-Stewart Algorithm Run #2 (76, 77, 78)
	- Bartels-Stewart Algorithm Run #3 (79, 80)
	- Bartels-Stewart Algorithm Run #4 (81, 82)
	- Bartels-Stewart Algorithm Run #5 (83, 84)
	- Bartels-Stewart Algorithm Run #6 (85, 86, 87)
	- Bartels-Stewart Algorithm Run #7 (88, 89, 90)
	- Bartels-Stewart Algorithm Run #8 (91, 92, 93)
	- Bartels-Stewart Algorithm Run #9 (94, 95, 96)
	- Bartels-Stewart Algorithm Run #10 (97, 98, 99)
	- Bartels-Stewart Algorithm Run #11 (100, 101, 102)
	- Bartels-Stewart Algorithm Run #12 (103, 104, 105)
	- Bartels-Stewart Algorithm Run #13 (106, 107, 108)
	- Bartels-Stewart Algorithm Run #14 (109, 110, 111)
	- Bartels-Stewart Algorithm Run #15 (112, 113, 114)
	- Bartels-Stewart Algorithm Run #16 (115, 116, 117)
	- Bartels-Stewart Algorithm Run #17 (118, 119, 120)


IdeaDRIP:

	- Alternating-direction Implicit Method Fundamental ADI (FADI) - Relations to other methods (1)
	- Bartels-Stewart Algorithm #1 (2-7)
	- The Bartels-Stewart Algorithm #1 (8-27)
	- Bartels-Stewart Algorithm Hessenberg-Schur #1 (28-31)
	- Bartels-Stewart Algorithm #2 (32-37)
	- The Bartels-Stewart Algorithm #2 (38-57)
	- Bartels-Stewart Algorithm Hessenberg-Schur #2 (58-61)
  • Loading branch information
Lakshmik committed Jul 13, 2024
1 parent ad64618 commit b9418cc
Show file tree
Hide file tree
Showing 10 changed files with 449 additions and 13 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
153 changes: 153 additions & 0 deletions IdeaDRIP/NumericalAnalysis/NA_v0.05
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@

--------------------------
#1 - Successive Over-Relaxation
--------------------------
--------------------------
1.1) Successive Over-Relaxation Method for A.x = b; A - n x n square matrix, x - unknown vector, b - RHS vector
1.2) Decompose A into Diagonal, Lower, and upper Triangular Matrices; A = D + L + U
1.3) SOR Scheme uses omega input
1.4) Forward subsitution scheme to iteratively determine the x_i's
1.5) SOR Scheme Linear System Convergence: Inputs A and D, Jacobi Iteration Matrix Spectral Radius, omega
- Construct Jacobi Iteration Matrix: C_Jacobian = I - (Inverse D) A
- Convergence Verification #1: Ensure that Jacobi Iteration Matrix Spectral Radius is < 1
- Convergence Verification #2: Ensure omega between 0 and 2
- Optimal Relaxation Parameter Expression in terms of Jacobi Iteration Matrix Spectral Radius
- Omega Based Convergence Rate Expression
- Gauss-Seidel omega = 1; corresponding Convergence Rate
- Optimal Omega Convergence Rate
1.6) Generic Iterative Solver Method:
- Inputs: Iterator Function(x) and omega
- Unrelaxed Iterated variable: x_n+1 = f(x_n)
- SOR Based Iterated variable: x_n+1 = (1-omega).x_n + omega.f(x_n)
- SOR Based Iterated variable for Unknown Vector x: x_n+1 = (1-omega).x_n + omega.(L_star inverse)(b - U.x_n)
--------------------------

--------------------------
#2 - Successive Over-Relaxation
--------------------------
--------------------------
2.1) SSOR Algorithm - Inputs; A, omega, and gamma
- Decompose into D and L
- Pre-conditioner Matrix: Expression from SSOR
- Finally SSOR Iteration Formula
--------------------------

----------------------------
#7 - Tridiagonal matrix algorithm
----------------------------
----------------------------
7.1) Is Tridiagonal Check
7.2) Core Algorithm:
- C Prime's and D Prime's Calculation
- Back Substitution for the Result
- Modified better Book-keeping algorithm
7.3) Sherman-Morrison Algorithm:
- Choice of gamma
- Construct Tridiagonal B from A and gamma
- u Column from gamma and c_n
- v Column from a_1 and gamma
- Solve for y from By=d
- Solve for q from Bq=u
- Use Sherman Morrison Formula to extract x
7.4) Alternate Boundary Condition Algorithm:
- Solve Au=d for u
- Solve Av={-a_2, 0, ..., -c_n} for v
- Full solution is x_i = u_i + x_1 * v_i
- x_1 if computed using formula
----------------------------

----------------------------
#8 - Triangular Matrix
----------------------------
----------------------------
8.1) Description:
- Lower/Left Triangular Verification
- Upper/Right Triangular Verification
- Diagonal Matrix Verification
- Upper/Lower Trapezoidal Verification
8.2) Forward/Back Substitution:
- Inputs => L and b
- Forward Substitution
- Inputs => U and b
- Back Substitution
8.3) Properties:
- Is Matrix Normal, i.e., A times A transpose = A transpose times A
- Characteristic Polynomial
- Determinant/Permanent
8.4) Special Forms:
- Upper/Lower Unitriangular Matrix Verification
- Upper/Lower Strictly Matrix Verification
- Upper/Lower Atomic Matrix Verification
----------------------------

----------------------------
#9 - Sylvester Equation
----------------------------
----------------------------
9.1) Matrix Form:
- Inputs: A, B, and C
- Size Constraints Verification
9.2) Solution Criteria:
- Co-joint EigenSpectrum between A and B
9.3) Numerical Solution:
- Decomposition of A/B using Schur Decomposition into Triangular Form
- Forward/Back Substitution
----------------------------

----------------------------
#10 - Bartels-Stewart Algorithm
----------------------------
----------------------------
10.1) Matrix Form:
- Inputs: A, B, and C
- Size Constraints Verification
10.2) Schur Decompositions:
- R = U^T A U - emits U and R
- S = V^T B^T V - emits V and S
- F = U^T C V
- Y = U^T X V
- Solution to R.Y - Y.S^T = F
- Finally X = U.Y.V^T
10.3) Computational Costs:
- Flops cost for Schur decomposition
- Flops cost overall
10.4) Hessenberg-Schur Decompositions:
- R = U^T A U becomes H = Q^T A Q - thus emits Q and H (Upper Hessenberg)
- Computational Costs
----------------------------

--------------------------
#12 - Crank–Nicolson method
--------------------------
--------------------------
12.1) von Neumann Stability Validator - Inputs; time-step, diffusivity, space step
- 1D => time step * diffusivity / space step ^2 < 0.5
- nD => time step * diffusivity / (space step hypotenuse) ^ 2 < 0.5
12.2) Set up:
- Input: Spatial variable x
- Input: Time variable t
- Inputs: State variable u, du/dx, d2u/dx2 - all at time t
- Second Order, 1D => du/dt = F (u, x, t, du/dx, d2u/dx2)
12.3) Finite Difference Evolution Scheme:
- Time Step delta_t, space step delta_x
- Forward Difference: F calculated at x
- Backward Difference: F calculated at x + delta_x
- Crank Nicolson: Average of Forward/Backward
12.4) 1D Diffusion:
- Inputs: 1D von Neumann Stability Validator, Number of time/space steps
- Time Index n, Space Index i
- Explicit Tridiagonal form for the discretization - State concentration at n+1 given state concentration at n
- Non-linear diffusion coefficient:
- Linearization across x_i and x_i+1
- Quasi-explicit forms accommodation
12.5) 2D Diffusion:
- Inputs: 2D von Neumann Stability Validator, Number of time/space steps
- Time Index n, Space Index i, j
- Explicit Tridiagonal form for the discretization - State concentration at n+1 given state concentration at n
- Explicit Solution using the Alternative Difference Implicit Scheme
12.6) Extension to Iterative Solver Schemes above:
- Input: State Space "velocity" dF/du
- Input: State "Step Size" delta_u
- Fixed Point Iterative Location Scheme
- Relaxation Scheme based Robustness => Input: Relaxation Parameter
--------------------------
11 changes: 9 additions & 2 deletions NumericalAnalysisLibrary.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,19 @@ Numerical Analysis Library contains the supporting Functionality for Numerical M
* Crank–Nicolson for nonlinear problems
* Application in financial mathematics
* References
* Sylvester equation
* Sylvester Equation
* Existence and uniqueness of the solutions
* Roth's removal rule
* Numerical solutions
* References
* Crank–Nicolson Method
* Bartels–Stewart Algorithm
* Introduction
* The Algorithm
* Computational Cost
* Simplifications and Special Cases
* The Hessenberg–Schur algorithm
* References
* Triangular Matrix
* Description
* Forward and Back Substitution
* Forward Substitution
Expand Down
25 changes: 25 additions & 0 deletions ReleaseNotes/02_14_2024.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Features:

Bug Fixes/Re-organization:

Samples:

IdeaDRIP:

- Bartels-Stewart Algorithm The - Simplifications and Special Cases (1)
- Bartels-Stewart Algorithm The Hessenberg–Schur Algorithm (2-8)
- Bartels-Stewart Algorithm Software and Implementation (9-10)
- Bartels-Stewart Algorithm Alternate Approaches (11-15)
- Alternating-direction Implicit Method Introduction (16-21)
- Alternating-direction Implicit Method ADI for Matrix Equations - The (22-29)
- Alternating-direction Implicit Method ADI for Matrix Equations - When to use (30-47)
- Alternating-direction Implicit Method ADI for Matrix Equations - Shift-parameter Selection and the Error Equation (48-57)
- Alternating-direction Implicit Method ADI for Matrix Equations - Shift-parameter Selection and the Error Equation - Near-optimal Shift Parameters (58-67)
- Alternating-direction Implicit Method ADI for Matrix Equations - Shift-parameter Selection and the Error Equation - Heuristic Strategies (68-73)
- Alternating-direction Implicit Method ADI for Matrix Equations - Factored (74-79)
- Alternating-direction Implicit Method ADI for Parabolic Equations (80-85)
- Alternating-direction Implicit Method ADI for Parabolic Equations - 2D Diffusion Equations (86-107)
- Alternating-direction Implicit Method ADI for Parabolic Equations - Generalizations (108-109)
- Alternating-direction Implicit Method Fundamental ADI (FADI) - Simplification of to (110-115)
- Alternating-direction Implicit Method Fundamental ADI (FADI) - Relations to other methods (116-120)
45 changes: 45 additions & 0 deletions ReleaseNotes/02_15_2024.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

Features:

- Bartels-Stewart Algorithm Diagnostics #1 (63, 64)
- Bartels-Stewart Algorithm Diagnostics #2 (65, 66)
- Sylvester Equation Solution Annotated Shell (67, 68, 69)


Bug Fixes/Re-organization:

- Numerical Analyzer Bartels-Stewart Algorithm (62)


Samples:

- QR Decomposition Matrix Util (63, 64)
- Graham Schmidt Matrix Orthonormalization Process (70, 71, 72)
- Bartels-Stewart Algorithm Run #1 (73, 74, 75)
- Bartels-Stewart Algorithm Run #2 (76, 77, 78)
- Bartels-Stewart Algorithm Run #3 (79, 80)
- Bartels-Stewart Algorithm Run #4 (81, 82)
- Bartels-Stewart Algorithm Run #5 (83, 84)
- Bartels-Stewart Algorithm Run #6 (85, 86, 87)
- Bartels-Stewart Algorithm Run #7 (88, 89, 90)
- Bartels-Stewart Algorithm Run #8 (91, 92, 93)
- Bartels-Stewart Algorithm Run #9 (94, 95, 96)
- Bartels-Stewart Algorithm Run #10 (97, 98, 99)
- Bartels-Stewart Algorithm Run #11 (100, 101, 102)
- Bartels-Stewart Algorithm Run #12 (103, 104, 105)
- Bartels-Stewart Algorithm Run #13 (106, 107, 108)
- Bartels-Stewart Algorithm Run #14 (109, 110, 111)
- Bartels-Stewart Algorithm Run #15 (112, 113, 114)
- Bartels-Stewart Algorithm Run #16 (115, 116, 117)
- Bartels-Stewart Algorithm Run #17 (118, 119, 120)


IdeaDRIP:

- Alternating-direction Implicit Method Fundamental ADI (FADI) - Relations to other methods (1)
- Bartels-Stewart Algorithm #1 (2-7)
- The Bartels-Stewart Algorithm #1 (8-27)
- Bartels-Stewart Algorithm Hessenberg-Schur #1 (28-31)
- Bartels-Stewart Algorithm #2 (32-37)
- The Bartels-Stewart Algorithm #2 (38-57)
- Bartels-Stewart Algorithm Hessenberg-Schur #2 (58-61)
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,23 @@
public class BartelsStewartScheme
{
private double[][] _rhsMatrix = null;
private boolean _diagnosticsOn = false;
private SylvesterEquation _sylvesterEquation = null;

/**
* <i>BartelsStewartScheme</i> Constructor
*
* @param sylvesterEquation Sylvester Equation Instance
* @param rhsMatrix "RHS" Matrix
* @param diagnosticsOn Diagnostics-on Flag
*
* @throws Exception Thrown if the Inputs are Invalid
*/

public BartelsStewartScheme (
final SylvesterEquation sylvesterEquation,
final double[][] rhsMatrix)
final double[][] rhsMatrix,
final boolean diagnosticsOn)
throws Exception
{
if (null == (_sylvesterEquation = sylvesterEquation) ||
Expand Down Expand Up @@ -168,6 +171,17 @@ public SylvesterEquation sylvesterEquation()
* @return "RHS" Matrix
*/

public boolean diagnosticsOn()
{
return _diagnosticsOn;
}

/**
* Retrieve the Diagnostics On Flag
*
* @return Diagnostics On Flag
*/

public double[][] rhsMatrix()
{
return _rhsMatrix;
Expand All @@ -179,20 +193,94 @@ public void solve()

System.out.println();

for (int i = 0; i < qrA.q().length; ++i) {
double[][] u = qrA.q();

for (int i = 0; i < u.length; ++i) {
System.out.println (
"\t| Matrix U => [" + NumberUtil.ArrayRow (u[i], 2, 4, false) + " ]||"
);
}

System.out.println();

double[][] r = qrA.r();

for (int i = 0; i < r.length; ++i) {
System.out.println (
"\t| Matrix R => [" + NumberUtil.ArrayRow (r[i], 2, 4, false) + " ]||"
);
}

System.out.println();

QR qrBTranspose = MatrixUtil.QRDecomposition (
_sylvesterEquation.squareMatrixB().transpose().r2Array()
);

double[][] v = qrBTranspose.q();

for (int i = 0; i < v.length; ++i) {
System.out.println (
"\t| Matrix Q => [" + NumberUtil.ArrayRow (qrA.q()[i], 2, 4, false) + " ]||"
"\t| Matrix V => [" + NumberUtil.ArrayRow (v[i], 2, 4, false) + " ]||"
);
}

System.out.println();

for (int i = 0; i < qrA.r().length; ++i) {
double[][] s = qrBTranspose.r();

for (int i = 0; i < s.length; ++i) {
System.out.println (
"\t| Matrix R => [" + NumberUtil.ArrayRow (qrA.r()[i], 2, 4, false) + " ]||"
"\t| Matrix S => [" + NumberUtil.ArrayRow (s[i], 2, 4, false) + " ]||"
);
}

double[][] f = MatrixUtil.Product (MatrixUtil.Transpose (u), _rhsMatrix);

f = MatrixUtil.Product (f, v);

System.out.println();

for (int i = 0; i < f.length; ++i) {
System.out.println (
"\t| Matrix F => [" + NumberUtil.ArrayRow (f[i], 2, 4, false) + " ]||"
);
}

double[][] y = new double[f.length][f.length];

for (int i = 0; i < f.length; ++i) {
for (int j = 0; j < f.length; ++j) {
y[i][j] = 0.;
}
}

for (int i = f.length - 1; i >= 0 ; --i) {
for (int j = f.length - 1; j >= 0; --j) {
double coefficientIJ = 0.;
double ryCumulativeSum = 0.;
double syCumulativeSum = 0.;

for (int k = i; k < f.length; ++k) {
if (k == i) {
coefficientIJ += r[i][k];
} else {
ryCumulativeSum += r[i][k] * y[k][j];
}
}

for (int k = j; k < f.length; ++k) {
if (k == j) {
coefficientIJ += r[i][k];
} else {
syCumulativeSum += r[i][k] * y[k][j];
}
}

y[i][j] = (f[i][j] - ryCumulativeSum - syCumulativeSum) / coefficientIJ;
}
}

System.out.println();
}

Expand All @@ -219,7 +307,8 @@ public static final void main (
SquareMatrix.Standard (matrixA),
SquareMatrix.Standard (matrixB)
),
matrixC
matrixC,
true
);

bartelsStewartScheme.solve();
Expand Down
Loading

0 comments on commit b9418cc

Please sign in to comment.