Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package metodo.biseccion;
- import java.util.ArrayList;
- public class Funcion {
- private int grado;
- private ArrayList<Termino> polinomio;
- public Funcion(int grado){
- this.grado=grado;
- polinomio = new ArrayList<>();
- }
- public void agregaTermino (double coeficiente, double exponente){
- Termino t = new Termino(coeficiente,exponente);
- polinomio.add(t);
- }
- public void agregaTerminoTrig(double coeficiente, double exponente, int tipo){
- TerminoTrig t = new TerminoTrig(coeficiente,exponente,tipo);
- polinomio.add(t);
- }
- public void mostrarFuncion(){
- System.out.print("f(x)=");
- for(int i=0;i<polinomio.size();i++){
- double exp,coef;
- Termino t=(Termino)polinomio.get(i);
- if(t instanceof Termino){
- TerminoTrig t2 = (TerminoTrig)t;
- switch (t2.getTipo()){
- case 1:
- exp=t.getExponente();
- coef=t.getCoeficiente();
- System.out.print(coef+" Sen"+"^"+exp+"(x) +");
- break;
- case 2:
- exp=t.getExponente();
- coef=t.getCoeficiente();
- System.out.print(coef+" Cos"+"^"+exp+"(x) +");
- break;
- case 3:
- exp=t.getExponente();
- coef=t.getCoeficiente();
- System.out.print(" "+coef+"Tan^"+exp+"(x) +");
- break;
- }
- }
- else{
- exp=t.getExponente();
- coef=t.getCoeficiente();
- System.out.print(" "+coef+"x^"+exp+" +");
- }
- }
- }
- }
- package metodo.biseccion;
- import java.math.*;
- public class Termino {
- protected double coeficiente;
- protected double exponente;
- public double getCoeficiente() {
- return coeficiente;
- }
- public double getExponente() {
- return exponente;
- }
- public Termino (double coeficiente, double exponente){
- this.coeficiente=coeficiente;
- this.exponente=exponente;
- }
- public double obtenerValor(double x){
- return (Math.pow(x, exponente)*coeficiente);
- }
- }
- public class TerminoTrig extends Termino{
- private final int tipo;
- public TerminoTrig(double coeficiente, double exponente, int tipo) {
- super(coeficiente, exponente);
- this.tipo=tipo;
- }
- /**
- *
- * @return
- */
- public int getTipo() {
- return tipo;
- }
- public double ObtenerValor(double x){
- switch (tipo){
- case 1:
- return (Math.pow(Math.sin(x),exponente))*coeficiente;
- case 2:
- return (Math.pow(Math.cos(x),exponente))*coeficiente;
- case 3:
- return (Math.pow(Math.tan(x),exponente))*coeficiente;
- default:
- System.out.println("El tipo de funcion es incorrecto");
- return 0;
- }
- }
- }
Add Comment
Please, Sign In to add comment