From that, you said that you wanted to be able to compute the "general case for 'n', where n is the number of items in a series that looks similar to the example above I.e:(Series 1) 30 29 1 ---- + ---- + ... + ---- 1 2 30
If you were computing the sum for 'n-1', wouldn't you want the sum:(Formula for Series 1) ( (n+1-k) ) Sum ( ------- ) for k = (1..n); ( k )
That's not what your code generates, either. That's what I meant by 'fixing' the code -- making it consistent with which-ever series you wanted (top one for 'n' or bottom one for 'n-1'). But the program you implemented doesn't generate either series because it doesn't implement the formula to generate that series but instead, for n=30, generates the series:(Series 2) 29 28 1 ---- + ---- + ... + ---- 1 2 29
That series is backwards from your original example, the code always divides by zero at the end the inner "for-loop", and skips the inner for-loop entirely, on the first iteration through the outer for-loop, making the sum, "$s", equal to "0". So the first time through the outer loop, you try to call $s->numerator & $s->denominator, but you've called them when $s=0 and no calculations have been done, thus the exception.(Series 3) 1 2 30 ---- + ---- + ... + ---- 29 28 0
Where you wanting to discover something different? :-)
In reply to Re^3: issues using bigrat
by perl-diddler
in thread issues using bigrat
by pc88mxer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |