QR decomposition: Difference between revisions
Content added Content deleted
m (→Using Colt) |
(→{{header|Java}}: +Commons Math) |
||
Line 1,929:
=={{header|Java}}==
===
Compile with: '''javac -cp Jama-1.0.3.jar Decompose.java'''.
Line 1,961:
0.0000 0.0000 35.0000</pre>
===
Compile with: '''javac -cp colt.jar
<lang java>import cern.colt.matrix.impl.DenseDoubleMatrix2D;
import cern.colt.matrix.linalg.QRDecomposition;
public class
public static void main(String[] args) {
var a = new DenseDoubleMatrix2D(new double[][] {{12, -51, 4},
Line 1,993:
0 -175 70
0 0 35</pre>
=== Apache Commons Math ===
Using the Apache Commons [http://commons.apache.org/proper/commons-math/ Math] library.
Compile with: '''javac -cp commons-math3-3.6.1.jar Decompose.java'''.
<lang java>import java.util.Locale;
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
import org.apache.commons.math3.linear.QRDecomposition;
import org.apache.commons.math3.linear.RealMatrix;
public class Decompose {
public static void main(String[] args) {
var a = new Array2DRowRealMatrix(new double[][] {{12, -51, 4},
{ 6, 167, -68},
{-4, 24, -41}});
var qr = new QRDecomposition(a);
print(qr.getQ());
System.out.println();
print(qr.getR());
}
public static void print(RealMatrix a) {
for (double[] u: a.getData()) {
System.out.print("[ ");
for (double x: u) {
System.out.printf(Locale.ROOT, "%10.4f ", x);
}
System.out.println("]");
}
}
}</lang>
{{out}}
<pre>[ -0.8571 0.3943 -0.3314 ]
[ -0.4286 -0.9029 0.0343 ]
[ 0.2857 -0.1714 -0.9429 ]
[ -14.0000 -21.0000 14.0000 ]
[ 0.0000 -175.0000 70.0000 ]
[ 0.0000 0.0000 35.0000 ]</pre>
=={{header|Julia}}==
|