Results 1 to 4 of 4
Thread: what am i doing wrong here?
- 03-21-2010, 02:18 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 20
- Rep Power
- 0
what am i doing wrong here?
I'm using an arraylist to multiply polynomials, but it doesn't work correctly:
Java Code:public void times (Poly b) { for ( int p_a = 0 ; p_a < polynomial.size() ; p_a++ ) { Term temp = polynomial.get(p_a); for ( int p_b = 0 ; p_b < b.polynomial.size() ; p_b++ ) { polynomial.set(p_a,temp.times(b.polynomial.get(p_b))); } } }ex. (x^2+3x-1)*(7-x^2+2x^3)Java Code:public Term times (Term term) { Term temp = new Term(coefficient *= term.coefficient, exponent += term.exponent); return temp; }
The correct answer would be 2x^5+5x^4-5x^3+8x^2+21x-7,
but in stead it gives me -14x^7-42x^6+14x^5
I believe this is because it updates polynomial(p_a) after each loop and uses that new value in the next loop. Which is odd, because I put in a temp Term for exactly that reason.
- 03-21-2010, 02:29 PM #2
Member
- Join Date
- Feb 2010
- Posts
- 20
- Rep Power
- 0
Oh I think I got it already, I never add the terms, I just change them.
- 03-21-2010, 03:08 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 20
- Rep Power
- 0
Hmm no, I'm still stuck.
- 03-21-2010, 04:04 PM #4
Member
- Join Date
- Feb 2010
- Posts
- 20
- Rep Power
- 0
Similar Threads
-
Wrong output (well.. the one who's wrong is probably me ;) )
By shacht1 in forum New To JavaReplies: 2Last Post: 11-22-2009, 03:48 PM -
Please help, what am I doing wrong?
By mmac1218 in forum New To JavaReplies: 2Last Post: 09-01-2009, 11:21 PM -
what am i doing wrong here??
By tornbacchus in forum New To JavaReplies: 19Last Post: 04-16-2009, 03:54 AM -
What did i do wrong
By jpnym15 in forum New To JavaReplies: 8Last Post: 11-17-2008, 10:07 AM -
right or wrong
By jot321 in forum New To JavaReplies: 7Last Post: 09-25-2008, 11:45 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks