Skip to content

Commit 4d6fe6f

Browse files
committed
Features:
- Numerical Linear Algebra SOR Standard (1, 2, 3) - Numerical Linear Algebra SOR Omega (4, 5, 6) - Numerical Linear Algebra SOR Square (7, 8, 9) - Linear Algebra SOR RHS Array (10, 11, 12) - SOR Projective Forward Substitution #1 (13, 14, 15) - SOR Projective Forward Substitution #2 (16, 17, 18) - Successive Over Relaxation Vector Match #1 (19, 20, 21) - Successive Over Relaxation Vector Match #2 (22, 23, 24) - Successive Over Relaxation Vector Match #3 (25, 26, 27) - Privatize SOR Vector Comparison Match (28) - Forward Substitution Major Element Identification (29, 30, 31) - Updated Unknown Array Major Element (32, 33) - Forward Substitution Vectors Match Exception (34) - SOR Previous/Updated Array #1 (35, 36) - SOR Previous/Updated Array #2 (37, 38) - SOR Forward Substitution Run #1 (39) - SOR Forward Substitution Run #2 (40, 41) - SOR Forward Substitution Run #3 (42, 43) - SOR Forward Substitution Run #4 (44, 45) - SOR Forward Substitution Run #5 (46, 47) - SOR Forward Substitution Run #6 (48, 49) - SOR Forward Substitution Run #7 (50, 51) - SOR Forward Substitution Run #8 (52, 53) - SOR Forward Substitution Run #9 (54, 55) - SOR Forward Substitution Run #10 (56, 57) - SOR Forward Substitution Run #11 (58, 59, 60) Bug Fixes/Re-organization: Samples: IdeaDRIP:
1 parent d0298a1 commit 4d6fe6f

File tree

3 files changed

+204
-5
lines changed

3 files changed

+204
-5
lines changed

ReleaseNotes/12_28_2023.txt

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
Features:
3+
4+
- Numerical Linear Algebra SOR Standard (1, 2, 3)
5+
- Numerical Linear Algebra SOR Omega (4, 5, 6)
6+
- Numerical Linear Algebra SOR Square (7, 8, 9)
7+
- Linear Algebra SOR RHS Array (10, 11, 12)
8+
- SOR Projective Forward Substitution #1 (13, 14, 15)
9+
- SOR Projective Forward Substitution #2 (16, 17, 18)
10+
- Successive Over Relaxation Vector Match #1 (19, 20, 21)
11+
- Successive Over Relaxation Vector Match #2 (22, 23, 24)
12+
- Successive Over Relaxation Vector Match #3 (25, 26, 27)
13+
- Privatize SOR Vector Comparison Match (28)
14+
- Forward Substitution Major Element Identification (29, 30, 31)
15+
- Updated Unknown Array Major Element (32, 33)
16+
- Forward Substitution Vectors Match Exception (34)
17+
- SOR Previous/Updated Array #1 (35, 36)
18+
- SOR Previous/Updated Array #2 (37, 38)
19+
- SOR Forward Substitution Run #1 (39)
20+
- SOR Forward Substitution Run #2 (40, 41)
21+
- SOR Forward Substitution Run #3 (42, 43)
22+
- SOR Forward Substitution Run #4 (44, 45)
23+
- SOR Forward Substitution Run #5 (46, 47)
24+
- SOR Forward Substitution Run #6 (48, 49)
25+
- SOR Forward Substitution Run #7 (50, 51)
26+
- SOR Forward Substitution Run #8 (52, 53)
27+
- SOR Forward Substitution Run #9 (54, 55)
28+
- SOR Forward Substitution Run #10 (56, 57)
29+
- SOR Forward Substitution Run #11 (58, 59, 60)
30+
31+
32+
Bug Fixes/Re-organization:
33+
34+
Samples:
35+
36+
IdeaDRIP:

ScheduleSheet.xlsx

-7 Bytes
Binary file not shown.

src/main/java/org/drip/numerical/linearalgebra/SuccessiveOverRelaxation.java

+168-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
package org.drip.numerical.linearalgebra;
33

4+
import org.drip.numerical.common.NumberUtil;
5+
import org.drip.service.common.FormatUtil;
6+
47
/*
58
* -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
69
*/
@@ -120,20 +123,49 @@
120123

121124
public class SuccessiveOverRelaxation
122125
{
126+
public static final double TOLERANCE = 1.0e-04;
127+
128+
private double[] _rhsArray = null;
129+
private double _omega = Double.NaN;
130+
private double[][] _squareMatrix = null;
123131
private double[][] _diagonalMatrix = null;
124132
private double[][] _strictlyLowerTriangularMatrix = null;
125133
private double[][] _strictlyUpperTriangularMatrix = null;
126134

135+
private static final boolean VectorsMatch (
136+
final double[] array1,
137+
final double[] array2)
138+
throws Exception
139+
{
140+
for (int i = 0; i < array1.length; ++i) {
141+
System.out.println ("Arrays => " + array1[i] + " | " + array2[i]);
142+
143+
if (Math.abs (array1[i] - array2[i]) > TOLERANCE) {
144+
System.out.println ("FALSE => " + Math.abs (array1[i] - array2[i]));
145+
146+
return false;
147+
}
148+
}
149+
150+
System.out.println ("TRUE");
151+
152+
return true;
153+
}
154+
127155
/**
128156
* Construct a Standard <i>SuccessiveOverRelaxation</i> Instance from the Square Matrix
129157
*
130158
* @param squareMatrix Square Matrix
159+
* @param rhsArray RHS Array
160+
* @param omega SOR Omega Parameter
131161
*
132162
* @return <i>SuccessiveOverRelaxation</i> Instance
133163
*/
134164

135165
public static final SuccessiveOverRelaxation Standard (
136-
final double[][] squareMatrix)
166+
final double[][] squareMatrix,
167+
final double[] rhsArray,
168+
final double omega)
137169
{
138170
try {
139171
int size = squareMatrix.length;
@@ -160,9 +192,12 @@ public static final SuccessiveOverRelaxation Standard (
160192
}
161193

162194
return new SuccessiveOverRelaxation (
195+
squareMatrix,
163196
diagonalMatrix,
164197
strictlyLowerTriangularMatrix,
165-
strictlyUpperTriangularMatrix
198+
strictlyUpperTriangularMatrix,
199+
rhsArray,
200+
omega
166201
);
167202
} catch (Exception e) {
168203
e.printStackTrace();
@@ -174,27 +209,47 @@ public static final SuccessiveOverRelaxation Standard (
174209
/**
175210
* <i>SuccessiveOverRelaxation</i> Constructor
176211
*
212+
* @param squareMatrix Square Matrix
177213
* @param diagonalMatrix Diagonal Matrix
178214
* @param strictlyLowerTriangularMatrix Strictly Lower Triangular Matrix
179215
* @param strictlyUpperTriangularMatrix Strictly Upper Triangular Matrix
216+
* @param rhsArray RHS Array
217+
* @param omega SOR Omega Parameter
180218
*
181219
* @throws Exception Thrown if the Inputs are Invalid
182220
*/
183221

184222
public SuccessiveOverRelaxation (
223+
final double[][] squareMatrix,
185224
final double[][] diagonalMatrix,
186225
final double[][] strictlyLowerTriangularMatrix,
187-
final double[][] strictlyUpperTriangularMatrix)
226+
final double[][] strictlyUpperTriangularMatrix,
227+
final double[] rhsArray,
228+
final double omega)
188229
throws Exception
189230
{
190-
if (null == (_diagonalMatrix = diagonalMatrix) ||
231+
if (null == (_squareMatrix = squareMatrix) ||
232+
null == (_diagonalMatrix = diagonalMatrix) ||
191233
null == (_strictlyLowerTriangularMatrix = strictlyLowerTriangularMatrix) ||
192-
null == (_strictlyUpperTriangularMatrix = strictlyUpperTriangularMatrix))
234+
null == (_strictlyUpperTriangularMatrix = strictlyUpperTriangularMatrix) ||
235+
null == (_rhsArray = rhsArray) ||
236+
!NumberUtil.IsValid (_omega = omega))
193237
{
194238
throw new Exception ("SuccessiveOverRelaxation Construction => Invalid Inputs");
195239
}
196240
}
197241

242+
/**
243+
* Retrieve the Square Matrix
244+
*
245+
* @return Square Matrix
246+
*/
247+
248+
public double[][] squareMatrix()
249+
{
250+
return _squareMatrix;
251+
}
252+
198253
/**
199254
* Retrieve the Diagonal Matrix
200255
*
@@ -227,4 +282,112 @@ public double[][] strictlyUpperTriangularMatrix()
227282
{
228283
return _strictlyUpperTriangularMatrix;
229284
}
285+
286+
/**
287+
* Retrieve the RHS Array
288+
*
289+
* @return RHS Array
290+
*/
291+
292+
public double[] rhsArray()
293+
{
294+
return _rhsArray;
295+
}
296+
297+
/**
298+
* Retrieve the SOR Omega
299+
*
300+
* @return SOR Omega
301+
*/
302+
303+
public double omega()
304+
{
305+
return _omega;
306+
}
307+
308+
public void forwardSubstitution (
309+
final double[] startingUnknownArray)
310+
{
311+
if (null == startingUnknownArray || _rhsArray.length != startingUnknownArray.length) {
312+
return;
313+
}
314+
315+
// int iteration = 0;
316+
double[] previousUnknownArray = startingUnknownArray;
317+
double[] updatedUnknownArray = new double[previousUnknownArray.length];
318+
319+
for (int i = 0; i < updatedUnknownArray.length; ++i) {
320+
updatedUnknownArray[i] = Math.random();
321+
}
322+
323+
try {
324+
do {
325+
previousUnknownArray = updatedUnknownArray;
326+
327+
for (int i = 0; i < previousUnknownArray.length; ++i) {
328+
updatedUnknownArray[i] = _rhsArray[i];
329+
330+
for (int j = 0; j < previousUnknownArray.length; ++j) {
331+
if (j < i) {
332+
updatedUnknownArray[i] -= _squareMatrix[i][j] * updatedUnknownArray[j];
333+
} else if (j > i) {
334+
updatedUnknownArray[i] -= _squareMatrix[i][j] * previousUnknownArray[j];
335+
}
336+
}
337+
338+
updatedUnknownArray[i] = (1. - _omega) * previousUnknownArray[i] + (
339+
_omega * updatedUnknownArray[i] / _squareMatrix[i][i]
340+
);
341+
342+
System.out.println (i + " => " + previousUnknownArray[i] + " | " + updatedUnknownArray[i]);
343+
}
344+
345+
/* String dump = "[Iteration = " + iteration++ + "] {";
346+
347+
for (int i = 0; i < previousUnknownArray.length; ++i) {
348+
dump += FormatUtil.FormatDouble (updatedUnknownArray[i], 2, 4, 1.) + " | " +
349+
FormatUtil.FormatDouble (previousUnknownArray[i], 2, 4, 1.) + ", ";
350+
}
351+
352+
System.out.println (dump + "}"); */
353+
} while (!VectorsMatch (previousUnknownArray, updatedUnknownArray));
354+
} catch (Exception e) {
355+
e.printStackTrace();
356+
}
357+
}
358+
359+
public static final void main (
360+
final String[] argumentArray)
361+
{
362+
double[][] squareMatrix = new double[][] {
363+
{ 4., -1., -6., 0.},
364+
{-5., -4., 10., 8.},
365+
{ 0., 9., 4., -2.},
366+
{ 1., 0., -7., 5.},
367+
};
368+
369+
double[] rhsArray = new double[] {
370+
2.,
371+
21.,
372+
-12.,
373+
-6.
374+
};
375+
376+
double omega = 0.5;
377+
378+
double[] startingUnknownArray = new double[] {
379+
0.,
380+
0.,
381+
0.,
382+
0.
383+
};
384+
385+
SuccessiveOverRelaxation successiveOverRelaxation = SuccessiveOverRelaxation.Standard (
386+
squareMatrix,
387+
rhsArray,
388+
omega
389+
);
390+
391+
successiveOverRelaxation.forwardSubstitution (startingUnknownArray);
392+
}
230393
}

0 commit comments

Comments
 (0)