Código
package polinomio public class Poli { private double coef[]; public Poli(){ } public Poli(double c[]){ coef=new double [c.length]; for (int i = 0; i < c.length; i++) { coef[i]=c[i]; } } public Poli (int g, double c){ coef=new double [g+1]; for (int i = 0; i <coef.length ; i++) { coef[i]=c; } } public Poli (Poli p){ this(p.coef); } public Poli(int g){ this(g,1); } public Poli(double c){ this(0,c); } public int ObtenerGrado(){ return coef.length-1; } public double obtenCoef(int t){ return coef[t]; } public double[] obtenTodosLosCoef(){ double aux[]=new double[coef.length]; for (int i = 0; i<coef.length; i++) { aux[i]=coef[i];} return aux; } public double obtenCoefInd(){ return 0; } public void negado(){ for (int i = 0; i < coef.length; i++) { coef[i]=-coef[i]; } } public void suma(Poli b){ Poli aux= new Poli(b); if (aux.coef.length>=coef.length) { for (int i = 0; i < coef.length; i++) { aux.coef[i]+=coef[i]; } } else{ for (int i = 0; i < aux.coef.length; i++) { coef[i]+=aux.coef[i]; } } } public Polinomio suma2 (Poli b){ Poli aux= new Poli(b); Poli aux2= new Poli(b); if(aux.coef.length>=aux2.coef.length){ for (int i = 0; i < aux2.coef.length; i++) { aux2.coef[i]+=coef[i]; } } else{ for (int i = 0; i < aux2.coef.length; i++) { coef[i]=aux2.coef[i]; } } return null; } public Poli resta(Poli p){ Poli aux=new Poli (p); aux.negado(); suma(aux); return aux; } public void multiplicar (Poli p){ Poli aux=new Poli(p); for (int i = 0; i < coef.length; i++) { } } public void derivada(){ } public double evalua(double x){ return 0; } public void ponCoef(int t,double c){ } @Override for (int i = 0; i < this.coef.length; i++) { if(coef[i]!=0){ aux=aux+"("+coef[i]+"x^"+i+")"+" + "; } } return aux; } }
Y aquí el main:
Código
package polinomio; public class Polinomio { Poli a,b,c; double datos1[]={3,1,5,6,9}; double datos2[]={8,4,-5,9,-8}; Polinomio p=new Polinomio(); a=new Poli(datos1); b=new Poli(datos2); c=new Poli(); //System.out.println("Polinomio a "+a); //System.out.println("Polinomio b "+b); // System.out.println("Polinomio c "+c); double datos3[]=b.obtenTodosLosCoef();//Para el obtenerTodosLosCoef for (int i = 0; i < datos3.length; i++) { // System.out.print(datos3[i]+" "); } b=new Poli(a); b.negado(); a.suma(b); } }
Sinceramente, llevo más de una semana con todo esto y ya estoy saliendo loco, no sé como hacer la multiplicación y la derivada, si alguien me pudiera ayudar se lo agradecería. Gracias de verdad.