Add new numerical methods to solve linear system:#531
Conversation
1. Thomas method (прогонки) 2. Jacobi method (iterative) 3. Seidel method (iterative, improvement version of the Jacobi method)
SPC-code
left a comment
There was a problem hiding this comment.
Methods should use LinearAlgebra and generalized for non-Float64 types.
Also, please add an example of usage in example module and a short markdown documentation on when those methods should be used.
| * @return vector X - solution of the system 'A*X=B'. | ||
| */ | ||
| @UnstableKMathAPI | ||
| public fun solveSystemByJacobiMethod( |
There was a problem hiding this comment.
Global namespace polution. The method must be made an extension for something. Using Double-only methods is not a KMath way, one should use Field or Ring if one does not need division for that.
| private var cachedMachineEpsilonPrecision: Double? = null | ||
|
|
||
| @UnstableKMathAPI | ||
| public val machineEpsilonPrecision: Double |
There was a problem hiding this comment.
Global namespace polution. And it should be Algebra attribute.
| } | ||
| } | ||
|
|
||
| var X: Point<Double> = initialApproximation |
| return X | ||
| } | ||
|
|
||
| private fun calcNorm(x1: Point<Double>, x2: Point<Double>): Double { |
There was a problem hiding this comment.
The function could be moved inside the only function it is used in
|
|
||
| norm = calcNorm(X, xTmp) | ||
| X = xTmp | ||
| } while (norm > epsilonPrecision) |
| } | ||
| } | ||
|
|
||
| val X: MutableStructure1D<Double> = initialApproximation?.let { |
| return X | ||
| } | ||
|
|
||
| private fun calcNorm(x1: Point<Double>, x2: Point<Double>): Double { |
| * @return vector X - solution of the system 'A*X=B'. | ||
| */ | ||
| @UnstableKMathAPI | ||
| public fun solveSystemByThomasMethod( |
There was a problem hiding this comment.
Global namespace pollution and unnecessary specialization. The same as above.
| ) | ||
|
|
||
| assertEquals(4, result.size) | ||
| val absoluteTolerance = 0.00000000000001 |
There was a problem hiding this comment.
There is a test method for structure equality
| */ | ||
| @Test | ||
| fun exceptionTest1() = | ||
| Double.algebra.linearSpace.run { |
and unit tests.