Guest User

Untitled

a guest
Jan 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. package metodo.biseccion;
  2.  
  3. import java.util.ArrayList;
  4.  
  5.  
  6. public class Funcion {
  7. private int grado;
  8. private ArrayList<Termino> polinomio;
  9.  
  10. public Funcion(int grado){
  11. this.grado=grado;
  12. polinomio = new ArrayList<>();
  13. }
  14. public void agregaTermino (double coeficiente, double exponente){
  15. Termino t = new Termino(coeficiente,exponente);
  16. polinomio.add(t);
  17. }
  18. public void agregaTerminoTrig(double coeficiente, double exponente, int tipo){
  19. TerminoTrig t = new TerminoTrig(coeficiente,exponente,tipo);
  20. polinomio.add(t);
  21. }
  22. public void mostrarFuncion(){
  23. System.out.print("f(x)=");
  24. for(int i=0;i<polinomio.size();i++){
  25. double exp,coef;
  26. Termino t=(Termino)polinomio.get(i);
  27. if(t instanceof Termino){
  28. TerminoTrig t2 = (TerminoTrig)t;
  29. switch (t2.getTipo()){
  30. case 1:
  31. exp=t.getExponente();
  32. coef=t.getCoeficiente();
  33. System.out.print(coef+" Sen"+"^"+exp+"(x) +");
  34. break;
  35. case 2:
  36. exp=t.getExponente();
  37. coef=t.getCoeficiente();
  38. System.out.print(coef+" Cos"+"^"+exp+"(x) +");
  39. break;
  40. case 3:
  41. exp=t.getExponente();
  42. coef=t.getCoeficiente();
  43. System.out.print(" "+coef+"Tan^"+exp+"(x) +");
  44. break;
  45. }
  46. }
  47. else{
  48. exp=t.getExponente();
  49. coef=t.getCoeficiente();
  50. System.out.print(" "+coef+"x^"+exp+" +");
  51. }
  52. }
  53. }
  54. }
  55.  
  56. package metodo.biseccion;
  57. import java.math.*;
  58.  
  59. public class Termino {
  60. protected double coeficiente;
  61. protected double exponente;
  62.  
  63. public double getCoeficiente() {
  64. return coeficiente;
  65. }
  66.  
  67. public double getExponente() {
  68. return exponente;
  69. }
  70.  
  71. public Termino (double coeficiente, double exponente){
  72. this.coeficiente=coeficiente;
  73. this.exponente=exponente;
  74. }
  75.  
  76. public double obtenerValor(double x){
  77. return (Math.pow(x, exponente)*coeficiente);
  78. }
  79. }
  80.  
  81. public class TerminoTrig extends Termino{
  82. private final int tipo;
  83.  
  84. public TerminoTrig(double coeficiente, double exponente, int tipo) {
  85. super(coeficiente, exponente);
  86. this.tipo=tipo;
  87. }
  88.  
  89. /**
  90. *
  91. * @return
  92. */
  93. public int getTipo() {
  94. return tipo;
  95. }
  96.  
  97. public double ObtenerValor(double x){
  98. switch (tipo){
  99. case 1:
  100. return (Math.pow(Math.sin(x),exponente))*coeficiente;
  101. case 2:
  102. return (Math.pow(Math.cos(x),exponente))*coeficiente;
  103. case 3:
  104. return (Math.pow(Math.tan(x),exponente))*coeficiente;
  105. default:
  106. System.out.println("El tipo de funcion es incorrecto");
  107. return 0;
  108. }
  109. }
  110. }
Add Comment
Please, Sign In to add comment