Results 1 to 4 of 4
  1. #1
    javaprgr is offline Member
    Join Date
    Jul 2010
    Posts
    3
    Rep Power
    0

    Default Method for multiplying two polynomials

    Hello everyone,
    i am having problems writing a method which can multiply 2 polynomials. Can u help me out???
    this is what i have done:
    public Poly mult(Poly p) {
    int n = getDegree();
    int m = p.getDegree();
    Poly result = new Poly(m+n);
    int i,j;
    Poly a = p;
    float sum=0;
    float [] temp = new float[n+m+1];

    for (i=0; i<=n+m; i++){
    for(j=0;j<=m+n;j++){
    sum = sum+ coefficients[i] * p.getCoefficient(j);
    }
    int x = i+j;
    result.setCoefficient(x, sum);

    }
    return result;

    }

    in the main program, it will be run as q.mult(p);
    hope to hear from u soon!!!!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    You should impement a method addCoefficient and make it do what its name implies. Don't use that setCoefficient method.

    kind regards,

    Jos

  3. #3
    javaprgr is offline Member
    Join Date
    Jul 2010
    Posts
    3
    Rep Power
    0

    Default

    Why shud i implement addCoefficient? and where shud i add it??

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by javaprgr View Post
    Why shud i implement addCoefficient? and where shud i add it??
    Think of it: given the two polynomials: x^2+2*x+3 and 4*x^2+5*x+6 you have to multiply 9 different terms: x^2*4*x^2, x^2*5*x, x^2*6, 2*x*4*x*2, 2*x*5*x, 2*x*6, 3*x^2, 3*5*x, 3*6. If you look carefully several terms have the same exponent so you should add the coefficients, hence my suggesstion.

    kind regards,

    Jos

Similar Threads

  1. Polynomials Arithmetic
    By thisisIT in forum New To Java
    Replies: 3
    Last Post: 03-09-2010, 01:27 PM
  2. Multiplying Values of an Array
    By brmcdani in forum New To Java
    Replies: 3
    Last Post: 02-06-2010, 04:00 AM
  3. Multiplying Variables
    By rnavarro9 in forum New To Java
    Replies: 4
    Last Post: 12-03-2009, 08:10 AM
  4. [SOLVED] Multiplying Objects Problme
    By thelinuxguy in forum Advanced Java
    Replies: 7
    Last Post: 05-07-2009, 05:19 PM
  5. Root Finder for polynomials
    By gibsonrocker800 in forum Advanced Java
    Replies: 11
    Last Post: 01-03-2008, 11:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •