I have searched Google and stack exchange extensively and cannot find a solution that fits my needs.
I have a recursive formula in a Google Spreadsheet that can be represented as
F(0) = 0
F(1) = 5000
F(n) = F(n-1) + ((n-1) * 5000)
I can effectively calculate this with a long two column table with n values in column A and the recursive formula in column B which references the previous cell when needing to access F(n-1).
This approach is clunky, takes up space, and requires a separate table for every different calculation. In my sheet I need to calculate this formula for different values of F(0)
and it requires a separate table for each one.
What I want is a simple single cell with a formula that references another cell for the n value and calculates the result recursively all in the background, instead of taking up a whole set of space in a table somewhere in my sheet for it to do the recursion through multiple cells.
My spreadsheet to make it clearer:
Is this possible?
Best Answer
If you go to your spreadsheet I solved your problem (at least I think so) in the 'progress' sheet and wrote up an explanation for how it works. Here's a quick summary, since I realize that answering a stack exchange question with only a broken link is terribly frustrating to future readers.
I treated F(1) and F(0) as constants that simply need to be added on to the end of the equation. Their only purpose is to show me the initial difference (in this case 5000). For reference in formulas, I created custom named ranges (Data>Named ranges) and called the cell with the n value (happened to be
G2
) the rangen
. The cell withF(0)
is calledfzero
, andF(1)
is calledfone
.e.g. F(n) - F(n-1)
or in spreadsheet form (remembern
is a named range pointing toG2
):F(n)
value, I really only needed to add up the cell-to-cell differences of all the previousF(n)
values. e.g. the sum of the set{F(0), F(1), F(2), F(3), ..., F(n-1)}
. I accomplished this using the=sequence()
command. Here, I'm telling sequence to start at 0 and count up by increments of 1 in a column 1 wide until it has printed n numbers.F(0)
andF(1)
.I didn't really do any testing on slightly modified equations or different starting values of F, but I think it would probably work with this general structure and slight modifications. If it isn't working, you could try altering the value of n by replacing it with
n-1
orn+1
or even further like 2. I found a few times in development that my formula was close but it was off by one value of n and that modifying it in this way worked.