public class frmMetodo2 extends javax.swing.JFrame {
DefaultTableModel model = new DefaultTableModel();
DefaultTableModel model2 = new DefaultTableModel();
DefaultTableModel model3 = new DefaultTableModel();
public frmMetodo2() {
initComponents();
tblI.setModel(model);
tblI2.setModel(model2);
tblX.setModel(model3);
String titu[] = {"X","f(x)"};
String titu2[] = {"X0","X1"};
String titu3[] = {"X"};
model.setColumnIdentifiers(titu);
model2.setColumnIdentifiers(titu2);
model3.setColumnIdentifiers(titu3);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
double i,f,x0,f0;
i=0.0;
f=0.0;
x0=0;
f0=0;
String dat[] = new String[2];
String dat2[] = new String[2];
for(i=-50;i<50;i++){
f = Math.exp(i)-2*i-2;
dat[0] = i + "";
dat[1] = f + "";
model.addRow(dat);
if (f*f0<0) {
dat2[0] = x0+"";
dat2[1] = i + "";
model2.addRow(dat2);
}
x0=i;
f0=f;
}
}
private void metodoBi(double x0,double x1) {
double xm,f0,fm;
double e;
String X[] = new String[1];
xm = (x0 + x1)/2;
e = Math.abs((xm-x0)/xm);
if (e>0.01) {
f0 = Math.exp(x0)-2*x0-2;
fm = Math.exp(xm)-2*xm-2;
if (f0*fm<0) {
metodoBi(x0,xm);
} else {
metodoBi(xm,x1);
}
} else {
X[0] = xm+"";
model3.addRow(X);
}
}
private void btnCalcActionPerformed(java.awt.event.ActionEvent evt) {
int n = model2.getRowCount();
if (n>0) {
double x0 = Double.parseDouble(model2.getValueAt(0, 0).toString());
double x1 = Double.parseDouble(model2.getValueAt(0, 1).toString());
metodoBi(x0,x1);
x0 = Double.parseDouble(model2.getValueAt(1, 0).toString());
x1 = Double.parseDouble(model2.getValueAt(1, 1).toString());
metodoBi(x0,x1);
}
}
}
minuvasoft10@gmail.com
No hay comentarios:
Publicar un comentario