Documentos de Académico
Documentos de Profesional
Documentos de Cultura
/*
* Created on 27-feb-2005
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.welsungo.math.integral;
import org.nfunk.jep.JEP;
/**
* @author felipe
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class DefnIntegral {
/** Parser */
private JEP myParser;
public DefnIntegral() {
myParser = new JEP();
myParser.initFunTab(); // clear the contents of the function table
myParser.addStandardFunctions();
myParser.setTraverse(true);
}
/**
* @return Returns the desde.
*/
public double getDesde() {
return mDesde;
}
/**
* @param desde
* The desde to set.
*/
public void setDesde(double desde) {
mDesde = desde;
}
/**
* @return Returns the function.
*/
public String getFunction() {
return mFunction;
}
/**
* @param function
* The function to set.
*/
public void setFunction(String function) {
mFunction = function;
}
/**
* @return Returns the hasta.
*/
public double getHasta() {
return mHasta;
}
/**
* @param hasta
* The hasta to set.
*/
public void setHasta(double hasta) {
mHasta = hasta;
}
/**
* @return Returns the intervalo.
*/
public double getNumIntervalos() {
return mNumIntervalos;
}
/**
* @param intervalo
* The intervalo to set.
*/
public void setNumIntervalos(double pNumIntervalos) {
mNumIntervalos = pNumIntervalos;
}
/**
*
*/
public double getIntegral() {
// TODO
double sizeIntervalo = (mHasta - mDesde) / mNumIntervalos;
System.out.println("sizeIntervalo="+sizeIntervalo);
System.out.println("f(x="+aux+") = "+dblRes);
//Compute Integral
//Valor de la funcion en mDesde
this.setXValue(mDesde);
//this.parseExpression(mEvaluator.getFunction());
this.parseExpression(this.getFunction());
this.updateResult();
String strDesde = this.getResult();
double dblDesde = 0;
try {
dblDesde = Double.parseDouble(strDesde.trim());
} catch (NumberFormatException e){e.printStackTrace();}
System.out.println("f(x="+mDesde+") = "+dblDesde);
System.out.println("f(x="+mHasta+") = "+dblHasta);
/*
* for(double i=mDesde; i <mHasta; i+sizeIntervalo) { }
*/
return dblIntegral;
}
/**
* @return Returns the error.
*/
public String getError() {
return mError;
}
/**
* @param pError The error to set.
*/
public void setError(String pError) {
mError = pError;
}
/**
* @return Returns the result.
*/
public String getResult() {
return mResult;
}
/**
* @param pResult The result to set.
*/
public void setResult(String pResult) {
mResult = pResult;
}
/**
* @return Returns the myParser.
*/
public JEP getMyParser() {
return myParser;
}
/**
* @param pMyParser The myParser to set.
*/
public void setMyParser(JEP pMyParser) {
myParser = pMyParser;
}
/**
* @return Returns the xValue.
*/
public double getXValue() {
return xValue;
}
/**
* @param pValue The xValue to set.
*/
public void setXValue(double pValue) {
xValue = pValue;
}
}
BINARIO
VENTANA
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.SwingConstants;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Ventana frame = new Ventana();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Ventana() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 435, 241);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
GridBagLayout gbl_contentPane = new GridBagLayout();
gbl_contentPane.columnWidths = new int[]{0, 30, 0, 0, 0, 0};
gbl_contentPane.rowHeights = new int[]{30, 0, 0, 0, 0, 0, 0, 0, 0};
gbl_contentPane.columnWeights = new double[]{0.0, 1.0, 0.0, 0.0, 0.0,
Double.MIN_VALUE};
gbl_contentPane.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
Double.MIN_VALUE};
contentPane.setLayout(gbl_contentPane);