|
| 1 | + |
| 2 | +package org.drip.sample.sor; |
| 3 | + |
| 4 | +import org.drip.numerical.common.NumberUtil; |
| 5 | +import org.drip.numerical.linearalgebra.Matrix; |
| 6 | +import org.drip.service.env.EnvManager; |
| 7 | + |
| 8 | +/* |
| 9 | + * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
| 10 | + */ |
| 11 | + |
| 12 | +/*! |
| 13 | + * Copyright (C) 2025 Lakshmi Krishnamurthy |
| 14 | + * |
| 15 | + * This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics, |
| 16 | + * asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment |
| 17 | + * analytics, and portfolio construction analytics within and across fixed income, credit, commodity, |
| 18 | + * equity, FX, and structured products. It also includes auxiliary libraries for algorithm support, |
| 19 | + * numerical analysis, numerical optimization, spline builder, model validation, statistical learning, |
| 20 | + * graph builder/navigator, and computational support. |
| 21 | + * |
| 22 | + * https://lakshmidrip.github.io/DROP/ |
| 23 | + * |
| 24 | + * DROP is composed of three modules: |
| 25 | + * |
| 26 | + * - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/ |
| 27 | + * - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/ |
| 28 | + * - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/ |
| 29 | + * |
| 30 | + * DROP Product Core implements libraries for the following: |
| 31 | + * - Fixed Income Analytics |
| 32 | + * - Loan Analytics |
| 33 | + * - Transaction Cost Analytics |
| 34 | + * |
| 35 | + * DROP Portfolio Core implements libraries for the following: |
| 36 | + * - Asset Allocation Analytics |
| 37 | + * - Asset Liability Management Analytics |
| 38 | + * - Capital Estimation Analytics |
| 39 | + * - Exposure Analytics |
| 40 | + * - Margin Analytics |
| 41 | + * - XVA Analytics |
| 42 | + * |
| 43 | + * DROP Computational Core implements libraries for the following: |
| 44 | + * - Algorithm Support |
| 45 | + * - Computation Support |
| 46 | + * - Function Analysis |
| 47 | + * - Graph Algorithm |
| 48 | + * - Model Validation |
| 49 | + * - Numerical Analysis |
| 50 | + * - Numerical Optimizer |
| 51 | + * - Spline Builder |
| 52 | + * - Statistical Learning |
| 53 | + * |
| 54 | + * Documentation for DROP is Spread Over: |
| 55 | + * |
| 56 | + * - Main => https://lakshmidrip.github.io/DROP/ |
| 57 | + * - Wiki => https://github.com/lakshmiDRIP/DROP/wiki |
| 58 | + * - GitHub => https://github.com/lakshmiDRIP/DROP |
| 59 | + * - Repo Layout Taxonomy => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md |
| 60 | + * - Javadoc => https://lakshmidrip.github.io/DROP/Javadoc/index.html |
| 61 | + * - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal |
| 62 | + * - Release Versions => https://lakshmidrip.github.io/DROP/version.html |
| 63 | + * - Community Credits => https://lakshmidrip.github.io/DROP/credits.html |
| 64 | + * - Issues Catalog => https://github.com/lakshmiDRIP/DROP/issues |
| 65 | + * |
| 66 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 67 | + * you may not use this file except in compliance with the License. |
| 68 | + * |
| 69 | + * You may obtain a copy of the License at |
| 70 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 71 | + * |
| 72 | + * Unless required by applicable law or agreed to in writing, software |
| 73 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 74 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 75 | + * |
| 76 | + * See the License for the specific language governing permissions and |
| 77 | + * limitations under the License. |
| 78 | + */ |
| 79 | + |
| 80 | +/** |
| 81 | + * <i>DULDecomposition</i> demonstrates the Decomposition of a Square Matrix into Diagonal, Lower, and Upper |
| 82 | + * Triangular Matrices. The References are: |
| 83 | + * |
| 84 | + * <br><br> |
| 85 | + * <ul> |
| 86 | + * <li> |
| 87 | + * Greenbaum, A. (1997): <i>Iterative Methods for Solving Linear Systems</i> <b>Society for |
| 88 | + * Industrial and Applied Mathematics</b> Philadelphia, PA |
| 89 | + * </li> |
| 90 | + * <li> |
| 91 | + * Hackbusch, W. (2016): <i>Iterative Solution of Large Sparse Systems of Equations</i> |
| 92 | + * <b>Spring-Verlag</b> Berlin, Germany |
| 93 | + * </li> |
| 94 | + * <li> |
| 95 | + * Wikipedia (2023): Symmetric Successive Over-Relaxation |
| 96 | + * https://en.wikipedia.org/wiki/Symmetric_successive_over-relaxation |
| 97 | + * </li> |
| 98 | + * <li> |
| 99 | + * Wikipedia (2024): Successive Over-Relaxation |
| 100 | + * https://en.wikipedia.org/wiki/Successive_over-relaxation |
| 101 | + * </li> |
| 102 | + * <li> |
| 103 | + * Young, D. M. (1950): <i>Iterative methods for solving partial difference equations of elliptical |
| 104 | + * type</i> <b>Harvard University</b> Cambridge, MA |
| 105 | + * </li> |
| 106 | + * </ul> |
| 107 | + * |
| 108 | + * <br><br> |
| 109 | + * <ul> |
| 110 | + * <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li> |
| 111 | + * <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalAnalysisLibrary.md">Numerical Analysis Library</a></li> |
| 112 | + * <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">DROP API Construction and Usage</a></li> |
| 113 | + * <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/sor/README.md">Successive Over-relaxation Customization/Usage</a></li> |
| 114 | + * </ul> |
| 115 | + * <br><br> |
| 116 | + * |
| 117 | + * @author Lakshmi Krishnamurthy |
| 118 | + */ |
| 119 | + |
| 120 | +public class DULDecomposition |
| 121 | +{ |
| 122 | + |
| 123 | + /** |
| 124 | + * Entry Point |
| 125 | + * |
| 126 | + * @param argumentArray Command Line Argument Array |
| 127 | + * |
| 128 | + * @throws Exception Thrown on Error/Exception Situation |
| 129 | + */ |
| 130 | + |
| 131 | + public static final void main ( |
| 132 | + final String[] argumentArray) |
| 133 | + throws Exception |
| 134 | + { |
| 135 | + EnvManager.InitEnv ( |
| 136 | + "" |
| 137 | + ); |
| 138 | + |
| 139 | + double[][] squareMatrix = new double[][] { |
| 140 | + { 4., -1., -6., 0.}, |
| 141 | + {-5., -4., 10., 8.}, |
| 142 | + { 0., 9., 4., -2.}, |
| 143 | + { 1., 0., -7., 5.}, |
| 144 | + }; |
| 145 | + |
| 146 | + System.out.println ("\t|----------------------------------------------------------------------"); |
| 147 | + |
| 148 | + System.out.println ("\t| JACOBI ITERATION MATRIX "); |
| 149 | + |
| 150 | + System.out.println ("\t|----------------------------------------------------------------------"); |
| 151 | + |
| 152 | + NumberUtil.Print2DArrayPair ( |
| 153 | + "\t| SQUARE", |
| 154 | + " JACOBI ITERATION", |
| 155 | + squareMatrix, |
| 156 | + Matrix.JacobiIteration (squareMatrix), |
| 157 | + false |
| 158 | + ); |
| 159 | + |
| 160 | + System.out.println ("\t|----------------------------------------------------------------------"); |
| 161 | + |
| 162 | + System.out.println(); |
| 163 | + |
| 164 | + System.out.println(); |
| 165 | + |
| 166 | + System.out.println ("\t|----------------------------------------------------------------------"); |
| 167 | + |
| 168 | + System.out.println ("\t| DIAGONALIZED MATRIX "); |
| 169 | + |
| 170 | + System.out.println ("\t|----------------------------------------------------------------------"); |
| 171 | + |
| 172 | + NumberUtil.Print2DArrayPair ( |
| 173 | + "\t| SQUARE", |
| 174 | + " DIAGONAL", |
| 175 | + squareMatrix, |
| 176 | + Matrix.Diagonal (squareMatrix), |
| 177 | + false |
| 178 | + ); |
| 179 | + |
| 180 | + System.out.println ("\t|----------------------------------------------------------------------"); |
| 181 | + |
| 182 | + System.out.println(); |
| 183 | + |
| 184 | + System.out.println(); |
| 185 | + |
| 186 | + System.out.println ("\t|----------------------------------------------------------------------"); |
| 187 | + |
| 188 | + System.out.println ("\t| STRICTLY LOWER TRIANGULAR MATRIX "); |
| 189 | + |
| 190 | + System.out.println ("\t|----------------------------------------------------------------------"); |
| 191 | + |
| 192 | + NumberUtil.Print2DArrayPair ( |
| 193 | + "\t| SQUARE", |
| 194 | + " LOWER TRIANGULAR", |
| 195 | + squareMatrix, |
| 196 | + Matrix.StrictlyLowerTriangular (squareMatrix), |
| 197 | + false |
| 198 | + ); |
| 199 | + |
| 200 | + System.out.println ("\t|----------------------------------------------------------------------"); |
| 201 | + |
| 202 | + System.out.println(); |
| 203 | + |
| 204 | + System.out.println(); |
| 205 | + |
| 206 | + System.out.println ("\t|----------------------------------------------------------------------"); |
| 207 | + |
| 208 | + System.out.println ("\t| STRICTLY UPPER TRIANGULAR MATRIX "); |
| 209 | + |
| 210 | + System.out.println ("\t|----------------------------------------------------------------------"); |
| 211 | + |
| 212 | + NumberUtil.Print2DArrayPair ( |
| 213 | + "\t| SQUARE", |
| 214 | + " UPPER TRIANGULAR", |
| 215 | + squareMatrix, |
| 216 | + Matrix.StrictlyUpperTriangular (squareMatrix), |
| 217 | + false |
| 218 | + ); |
| 219 | + |
| 220 | + System.out.println ("\t|----------------------------------------------------------------------"); |
| 221 | + |
| 222 | + EnvManager.TerminateEnv(); |
| 223 | + } |
| 224 | +} |
0 commit comments