![]() |
Multi-dimensional vectors
I'm creating a program to help me solve polynomial multiplication so I won't have to do all that multiplying.(I'm lazy. :P)And I have run into a problem. I found that in order for the multiplication to turn out right I have to create dynamic two-dimensional arrays. I messed with
new for a bit until I just figured it would be more efficient to just use the vector class. But the problem is I keep on getting "Vector subscript out of range" when I get to a certain point in my program(commented bellow).:
Any pointers or help would be highly appreciated! Thanks. |
Re: Multi-dimensional vectors
The problem is with t in the inner loop. Because it's inside the loop, each time through, you'll reset it to 1, do your work, then increment it. The next time, you set it to 1 (note that j went up by 2), do your work, and increment... repeat as necessary. As it's coded, t will always be 1 when you do the calculations.
|
Re: Multi-dimensional vectors
I was so distracted by the large computations that I overlooked the little ones! :) Thanks.
EDIT It fixed that silly little slip-up but I'm still getting the error. EDIT |
Re: Multi-dimensional vectors
Can you post the new code? or even just the snippet
|
Re: Multi-dimensional vectors
Quote:
Here: :
|
Re: Multi-dimensional vectors
I ran it again, with 2 binomials. The inner loop condition is true
(num_poly - 1) == 1, so j >= num_poly - 1 will always be true. Then when you're indexing into coeff[j] you end up with an index greater than the size of the vector. Just thinking about it, if you ever had more than 2 binomials, the condition would be false and the loop would never run. You'll have to rework the logic on that one :icon_wink: |
Re: Multi-dimensional vectors
lol I'm missing a lot lately! :$ It's been a few months since I last programed, but I didn't expect to be this rusty... off to try it again I guess!
|
Re: Multi-dimensional vectors
All my work, foiled. :'( My friend told me a wrong way to multiply binomials, and now I have to start the initial algorithm from scratch again. Oh well, just more practice right?
|
Re: Multi-dimensional vectors
haha, nice perspective :D
|
Re: Multi-dimensional vectors
Well, I think I figured it out this time, now just a few hours of work... I hope. :(
|
| All times are GMT -5. The time now is 5:16 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC