lunes, 23 de abril de 2007

segundo ejemplo 23-04

/*
* DoWhile.java
*
* Created on 23 de abril de 2007, 07:25 PM
*/

/**
*
* @author ALUMNO
*/
public class DoWhile_1 extends javax.swing.JFrame {

/** Creates new form DoWhile */
public DoWhile_1() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// //GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextPane1 = new javax.swing.JTextPane();
jScrollPane3 = new javax.swing.JScrollPane();
jTextPane3 = new javax.swing.JTextPane();
jLabel3 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
jScrollPane4 = new javax.swing.JScrollPane();
jTextPane4 = new javax.swing.JTextPane();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("x");

jScrollPane1.setViewportView(jTextPane1);

jScrollPane3.setViewportView(jTextPane3);

jLabel3.setText("Raiz");

jButton1.setText("Evaluar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jLabel4.setText("Error");

jScrollPane4.setViewportView(jTextPane4);

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel3))
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel4)))
.add(18, 18, 18)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(jScrollPane4)
.add(jScrollPane3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE))
.addContainerGap(145, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap(168, Short.MAX_VALUE)
.add(jButton1)
.add(163, 163, 163))
.add(layout.createSequentialGroup()
.add(25, 25, 25)
.add(jLabel1)
.add(18, 18, 18)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(278, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(48, 48, 48)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jLabel1)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(42, 42, 42)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel3))
.add(14, 14, 14)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel4)
.add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(30, 30, 30)
.add(jButton1)
.addContainerGap(30, Short.MAX_VALUE))
);
pack();
}//
//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
double xi,x,Fxi,Fx,F1x,E;
int i;

x = Double.parseDouble(jTextPane1.getText());

/// f(x) = x*sin(x) - x*x + 5
// f'(x) = sin(x) + x*cos(x) - 2*x

// x -> xi
// f'(x) = F(x) /( xi - x)
// Xi = x + F(x) / f'(x)

i = 0;
while(i< 10){
Fx = x*Math.sin(x) - x*x + 5;
F1x = Math.sin(x) + x*Math.cos(x) - 2*x;
xi = x + (Fx / F1x);
E = Math.abs(x-xi);
x = xi;
i++;
}
jTextPane3.setText(String.valueOf(xi));
jTextPane4.setText("+- "+String.valueOf(E));
}//GEN-LAST:event_jButton1ActionPerformed

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new DoWhile().setVisible(true);
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JTextPane jTextPane1;
private javax.swing.JTextPane jTextPane3;
private javax.swing.JTextPane jTextPane4;
// End of variables declaration//GEN-END:variables

}