QR decomposition: Difference between revisions
Content added Content deleted
(→{{header|Java}}: +Commons Math) |
m (→{{header|Java}}: +la4j) |
||
Line 1,930: | Line 1,930: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
=== Jama === |
=== Jama === |
||
Using the [https://math.nist.gov/javanumerics/jama/ Jama] library. |
Using the [https://math.nist.gov/javanumerics/jama/ Jama] library. Compile with: '''javac -cp Jama-1.0.3.jar Decompose.java'''. |
||
⚫ | |||
<lang java>import Jama.Matrix; |
<lang java>import Jama.Matrix; |
||
Line 1,963: | Line 1,961: | ||
=== Colt === |
=== Colt === |
||
Using the [https://dst.lbl.gov/ACSSoftware/colt/ Colt] library. |
Using the [https://dst.lbl.gov/ACSSoftware/colt/ Colt] library. Compile with: '''javac -cp colt.jar Decompose.java'''. |
||
Compile with: '''javac -cp colt.jar Decompose.java'''. |
|||
<lang java>import cern.colt.matrix.impl.DenseDoubleMatrix2D; |
<lang java>import cern.colt.matrix.impl.DenseDoubleMatrix2D; |
||
Line 1,972: | Line 1,968: | ||
public class Decompose { |
public class Decompose { |
||
public static void main(String[] args) { |
public static void main(String[] args) { |
||
var a = new DenseDoubleMatrix2D(new double[][] { |
var a = new DenseDoubleMatrix2D(new double[][] { |
||
{12, -51, 4}, |
|||
{ 6, 167, -68}, |
|||
{-4, 24, -41} |
|||
}); |
|||
var qr = new QRDecomposition(a); |
var qr = new QRDecomposition(a); |
||
System.out.println(qr.getQ()); |
System.out.println(qr.getQ()); |
||
Line 2,008: | Line 2,006: | ||
public class Decompose { |
public class Decompose { |
||
public static void main(String[] args) { |
public static void main(String[] args) { |
||
var a = new Array2DRowRealMatrix(new double[][] { |
var a = new Array2DRowRealMatrix(new double[][] { |
||
{12, -51, 4}, |
|||
{ 6, 167, -68}, |
|||
{-4, 24, -41} |
|||
}); |
|||
var qr = new QRDecomposition(a); |
var qr = new QRDecomposition(a); |
||
Line 2,038: | Line 2,038: | ||
[ 0.0000 -175.0000 70.0000 ] |
[ 0.0000 -175.0000 70.0000 ] |
||
[ 0.0000 0.0000 35.0000 ]</pre> |
[ 0.0000 0.0000 35.0000 ]</pre> |
||
=== la4j === |
|||
⚫ | |||
<lang java>import org.la4j.Matrix; |
|||
import org.la4j.decomposition.QRDecompositor; |
|||
public class Decompose { |
|||
public static void main(String[] args) { |
|||
var a = Matrix.from2DArray(new double[][] { |
|||
{12, -51, 4}, |
|||
{ 6, 167, -68}, |
|||
{-4, 24, -41}, |
|||
}); |
|||
Matrix[] qr = new QRDecompositor(a).decompose(); |
|||
System.out.println(qr[0]); |
|||
System.out.println(qr[1]); |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre>-0,857 0,394 -0,331 |
|||
-0,429 -0,903 0,034 |
|||
0,286 -0,171 -0,943 |
|||
-14,000 -21,000 14,000 |
|||
0,000 -175,000 70,000 |
|||
0,000 0,000 35,000</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |