3
I have the following function:
f(n) = f(n - 1) + (n - 1)
f(0) = 0
n >= 0
I have n
declared on column A, and need the result of f(n)
on column B.
I'm trying to find the Excel formula equivalent for this function.
Sample Result:
A | B
--+--
0 | 0
or:
A | B
--+--
1 | 0
or:
A | B
--+--
4 | 6
but never:
A | B
--+--
0 | 0
1 | 0
2 | 1
...
The biggest problem is, I can't simulate the value of f(n - 1)
. So referencing the previous row like the above example is invalid. I'm almost sure the answer is trivial, I just can't find it.
presumably f is just a stand in for a more complex recusive function – Scott Weinstein – 2009-08-03T23:22:04.493
@Scott Weinstein The question is the question. If am going to get downvoted for answering the question as it was posted, so be it. – Sinan Ünür – 2009-08-03T23:26:02.487
assuming that column A is going to be sequential then your example works. – Stan R. – 2009-08-03T23:29:47.987
Scott, the question doesn't imply that at all. If the question is intended to mean, "How can I perform a general recursive function in Excel?" than, well, that's what the question should say. The less snarky version of Sinan's (completely correct) answer is: f(n + 1) = (n^2 + n)/2 – WCWedin – 2009-08-03T23:31:12.633
good points, perhaps less presumption on my part... – Scott Weinstein – 2009-08-03T23:48:38.637
@WCWedin OK, I did get a little snarky. At first, I thought simply showing the formula would accomplish the required hand to forehead motion and that would have been it. Once programmers, not lay people, start posting user defined functions for a well known arithmetic formula, methinks it's time to be a little snarky. – Sinan Ünür – 2009-08-04T00:31:40.597
@Stan R What on earth do you mean by sequential. The only reason the numbers in the left-most column are sequential is convenience. I'll update that example for you. – Sinan Ünür – 2009-08-04T00:35:15.447
@Sinan: my apologies sir, I didn't notice that its the (value-1) not (cell-1). I haven't dealt with Excel in a while..should stick with C# :D – Stan R. – 2009-08-04T00:41:11.517
...ohhh and +1 :) – Stan R. – 2009-08-04T00:44:38.303
Right on Sinan, this is exactly what I need! Thanks! – Adrian Godong – 2009-08-04T06:05:00.423