Singular value decomposition: Difference between revisions
Content added Content deleted
m (→{{header|Wren}}: typo) |
(Add Java) |
||
Line 167: | Line 167: | ||
</pre> |
</pre> |
||
=={{header|Java}}== |
|||
{{works with|Java|10+}} |
|||
{{libheader|Jama}} |
|||
The library "Jama" can decompose m x n matrix though the example here is a 2 x 2 matrix. |
|||
If you want to use lower Java version, you need to replace the first "var" with "Matrix" and the second with "Singular |
|||
ValueDecomposition". You need also import "Jama.SingularValueDecomposition" and change the name of "public class" |
|||
<syntaxhighlight lang="java"> |
|||
import Jama.Matrix; |
|||
public class SingularValueDecomposition { |
|||
public static void main(String[] args) { |
|||
double[][] matrixArray = {{3, 0}, {4, 5}}; |
|||
var matrix = new Matrix(matrixArray); |
|||
var svd = matrix.svd(); |
|||
svd.getU().print(0, 10); // The number of digits after the decimal is 10. |
|||
svd.getS().print(0, 10); |
|||
svd.getV().print(0, 10); |
|||
} |
|||
} |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
0.3162277660 0.9486832981 |
|||
0.9486832981 -0.3162277660 |
|||
6.7082039325 0.0000000000 |
|||
0.0000000000 2.2360679775 |
|||
0.7071067812 0.7071067812 |
|||
0.7071067812 -0.7071067812 |
|||
</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
Julia has an svd() function as part of its built-in LinearAlgebra package. |
Julia has an svd() function as part of its built-in LinearAlgebra package. |