Solve2.java uses the class TextArea
which encapsulates a
JTextArea
and JScrollPane
Solve2.javaimport Jama.*;
import java.awt.*;
import javax.swing.*;
/** Example of use of Matrix Class **/
public class Solve2 {
static TextArea content = new TextArea();
/** Shorten spelling of print. **/
private static void print (String s) {
content.area.append(s);
}
private static void print(Matrix M, String fmt) {
//String fmt = "%8.4f";
int nrows = M.getRowDimension();
int ncols = M.getColumnDimension();
print("\n");
for (int i = 0; i<nrows; i++) {
for (int j=0; j<ncols; j++) {
print(String.format(fmt,M.get(i,j)));
}
print("\n");
}
}
public static void show_solve()
{
double a[][] = { {4, -2, 1}, {-3, -1, 4}, {1, -1, 3} };
double v[][] = { {15}, {8}, {13}};
Matrix A = new Matrix(a);
print("A = ");
print(A,"%8.1f");
Matrix b = new Matrix(v);
print("b = ");
print(b,"%8.1f");
Matrix x = A.solve(b);
print("x = ");
print(x,"%8.4f");
print("\n");
Matrix Residual = A.times(x).minus(b);
double rnorm = Residual.normInf();
print(String.format("residual = %g\n",rnorm));
}
public static void main (String argv[]) {
content.area.setFont(new Font(Font.MONOSPACED,Font.PLAIN,16));
show_solve();
JFrame win = new JFrame();
//... Set window characteristics.
win.setContentPane(content);
win.setTitle("Jama Demo");
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.pack();
win.setVisible(true);
}
}
Maintained by John Loomis, updated Fri Mar 27 11:38:26 2015