Numerical approximation for leaky tanks

34 Views Asked by At

I am going through the material from MIT OCW and I have one small problem with one of the tasks. Screenshot of the task.

In the part I'm having problem with, I'm supposed to use forward Euler approximation to calculate r1(t) and r2(t).

I get the following equation for r1:

r1[n] = T/20 * (r0[n-1] - r1[n-1]) + r1[n-1]

And, then r0 is held constant at 0.1:

r1[n] = T/20 * (0.1 - r1[n-1]) + r1[n-1]

So, I would expect it to be similar for r2:

r2[n] = T/10 * (r1[n-1] - r2[n-1]) + r2[n-1]

However, in the solutions for this assignment, the enclosed code is the following:

for i in range(1,60):
    r1.append(r1[i-1]+T/20.*(0.1-r1[i-1]))
    r2.append(r2[i-1]+T/10.*(r1[i]-r2[i-1]))

While I would expect the following line:

    r2.append(r2[i-1]+T/10.*(r1[i-1]-r2[i-1]))

So, why it should be r1[i] and not r1[i-1]? Thanks for any help.

PDF with full task & solution - Task 6.(f)