OK, some quick intro for you.
To store ready-made finite sequences, use lists:
x = [0, 1, 2, 2, 3, 3, 3, 3]
This lets you easily address each sequence element by index in brackets, 0 being the first index, so x[0] == 0
and x[4] == 3
.
Your function Ф could be defined as
def F(n, m, r, x):
return m * x[n] + (r / m) * (x[n + 1] - x[n])
So F(3, 2.0, 1.5, x) == 4.75
.
To see the function applied to the entire list x
, you can do something like this:
# we use len() - 1 because len(x) is the number of elements in x,
# and the last valid k for x[k] is len(x) - 1;
# F uses x[n+1], so n must not exceed len(x) - 2.
# But range(n) gives us numbers 0..n-1, so the last n we generate
# is (len(x) - 1) - 1, exactly what we need.
for n in range(len(x) - 1):
print n, F(n, 2.0, 1.5, x)
Now go read Python in 5 minutes and then Dive Into Python to understand things better. Though a math student might find Haskell more compelling, if not as easy :)