Skip to content

Commit ba73b9a

Browse files
committed
试图解决负的特征值
1 parent 3aa6bfc commit ba73b9a

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

  • src/main/kotlin/org/mechdancer/algebra/function/matrix

src/main/kotlin/org/mechdancer/algebra/function/matrix/Jocabi.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.mechdancer.algebra.function.matrix
22

3+
import org.mechdancer.algebra.DOUBLE_PRECISION
34
import org.mechdancer.algebra.core.Matrix
45
import org.mechdancer.algebra.core.Vector
56
import org.mechdancer.algebra.function.vector.component1
@@ -88,7 +89,7 @@ fun Matrix.svd(epsilon: Double = 1e-8): Triple<Matrix, Matrix, Matrix> {
8889

8990
fun partEvd(a: Matrix, at: Matrix): Triple<Matrix, Matrix, Matrix> {
9091
val (m, square) = (a * at).evd(epsilon)!!
91-
val s = square.diagonal.map(::sqrt)
92+
val s = square.diagonal.map { if (it < DOUBLE_PRECISION) .0 else sqrt(it) }
9293
val w = listMatrixOf(row, column) { r, c -> if (r == c) s[r] else .0 }
9394
val others = (at * m * DiagonalMatrix(s.map { 1 / it }))
9495
return Triple(m, w, others)

0 commit comments

Comments
 (0)