QR decomposition: Difference between revisions

Added Java example using JAMA matrix library
No edit summary
(Added Java example using JAMA matrix library)
Line 1,690:
1 2 3</lang>
'''Notes''':J offers a built-in QR decomposition function, <tt>128!:0</tt>. If J did not offer this function as a built-in, it could be written in J along the lines of the second version, which is covered in [[j:Essays/QR Decomposition|an essay on the J wiki]].
 
=={{header|Java}}==
Note: uses the [https://math.nist.gov/javanumerics/jama/ JAMA Java Matrix Package].
 
Compile with: '''javac -cp Jama-1.0.3.jar Decompose.java'''.
 
<lang java>import Jama.Matrix;
import Jama.QRDecomposition;
 
import java.io.StringWriter;
import java.io.PrintWriter;
 
public class Decompose {
public static void main(String[] args) {
Matrix matrix = new Matrix(new double[][] {
{ 12, -51, 4 },
{ 6, 167, -68 },
{ -4, 24, -41 },
});
 
QRDecomposition d = new QRDecomposition(matrix);
System.out.print(toString(d.getQ()));
System.out.print(toString(d.getR()));
}
 
public static String toString(Matrix m) {
StringWriter sw = new StringWriter();
m.print(new PrintWriter(sw, true), 8, 6);
return sw.toString();
}
}</lang>
 
{{out}}
<pre>
 
-0.857143 0.394286 -0.331429
-0.428571 -0.902857 0.034286
0.285714 -0.171429 -0.942857
 
 
-14.000000 -21.000000 14.000000
0.000000 -175.000000 70.000000
0.000000 0.000000 35.000000
</pre>
 
=={{header|Julia}}==