Metodos Numericos, Analisis Numerico.
import javax.swing.table.DefaultTableModel;
public class frmInversa extends javax.swing.JFrame {
DefaultTableModel modelA = new DefaultTableModel();
DefaultTableModel modelI = new DefaultTableModel();
public frmInversa() {
initComponents();
tblA.setModel(modelA);
tblI.setModel(modelI);
cargarA3();
}
private void cargarA5() {
modelA.setColumnCount(5);
modelI.setColumnCount(5);
String dat[] = new String[5];
dat[0] = "6.5"; dat[1]="2.5"; dat[2]="3.5"; dat[3]="4.5"; dat[4]="5.5";
modelA.addRow(dat);
dat[0] = "6"; dat[1]="7"; dat[2]="8"; dat[3]="9"; dat[4]="10";
modelA.addRow(dat);
dat[0] = "9"; dat[1]="8"; dat[2]="1.5"; dat[3]="6"; dat[4]="5";
modelA.addRow(dat);
dat[0] = "4"; dat[1]="3"; dat[2]="2"; dat[3]="11.5"; dat[4]="0";
modelA.addRow(dat);
dat[0] = "-1"; dat[1]="-2"; dat[2]="3"; dat[3]="-4"; dat[4]="5";
modelA.addRow(dat);
}
private void cargarA4() {
modelA.setColumnCount(4);
modelI.setColumnCount(4);
String dat[] = new String[4];
dat[0] = "1"; dat[1]="2"; dat[2]="3"; dat[3]="10";
modelA.addRow(dat);
dat[0] = "4"; dat[1]="5"; dat[2]="6"; dat[3]="11";
modelA.addRow(dat);
dat[0] = "7"; dat[1]="2"; dat[2]="9"; dat[3]="1";
modelA.addRow(dat);
dat[0] = "5.5"; dat[1]="2.5"; dat[2]="9.5"; dat[3]="1.5";
modelA.addRow(dat);
}
private void cargarA3() {
modelA.setColumnCount(3);
modelI.setColumnCount(3);
String dat[] = new String[3];
dat[0] = "1"; dat[1]="2"; dat[2]="3";
modelA.addRow(dat);
dat[0] = "4"; dat[1]="5"; dat[2]="6";
modelA.addRow(dat);
dat[0] = "7"; dat[1]="2"; dat[2]="9";
modelA.addRow(dat);
}
private void cargarA2() {
modelA.setColumnCount(2);
modelI.setColumnCount(2);
String dat[] = new String[2];
dat[0] = "1"; dat[1]="2";
modelA.addRow(dat);
dat[0] = "4"; dat[1]="5";
modelA.addRow(dat);
}
private void btnInvActionPerformed(java.awt.event.ActionEvent evt) { int i,j,k;
Deter D = new Deter();
int N = modelA.getRowCount();
modelI.setColumnCount(N);
modelI.setRowCount(0);
double adjA[][] = new double[N][N];
double A[][] = new double[N][N];
double T[][] = new double[N][N];
double X[][] = new double[N][N];
double detA;
String dato[] = new String[N];
for(i=0;i<N;i++) {
for(j=0;j<N;j++) {
A[i][j] = Double.parseDouble(modelA.getValueAt(i, j).toString());
}
}
detA = D.deterM(A, N);
lblDet.setText("det(A)= "+detA);
for(i=0;i<N;i++) {
for(j=0;j<N;j++) {
k=i+2+j;
D.obtener(A, T, i, j, N);
adjA[i][j] = Math.pow(-1, k)*D.deterM(T, N-1);
X[j][i] = adjA[i][j]/detA;
}
}
for(i=0;i<N;i++) {
for(j=0;j<N;j++) {
dato[j] = X[i][j]+"";
}
modelI.addRow(dato);
}
}
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) { int op = jComboBox1.getSelectedIndex();
modelA.setRowCount(0);
modelI.setRowCount(0);
lblDet.setText(null);
switch (op){
case 0: cargarA2(); break;
case 1: cargarA3(); break;
case 2: cargarA4(); break;
case 3: cargarA5(); break;
}
}
minuvasoft10@gmail.com Miguel Nunez - Se desarrolla proyectos software.
No hay comentarios:
Publicar un comentario