Please, help to understand the method which is used in the following snippet:
% delta - time step
% d - x step
% initialization
for all x from 0 to 1 in increments of delta
f[x,0] = 1/2 * x^2
% run the differential equation forward
for t from 0 to T in increments of d
% Compute the derivative
for all x
fderiv[x,t] = f[x,t] - f[x-d,t] % adjust this appropriately at the boundary x = 0
% Step the differential equation forward one unit
for all x from 0 to 1 in increments of delta
f[x,t+delta] = ( x - f[x,t])/fderiv[x,t] - x
% f[x, t+delta] must stay <= x and >= 0
if f[x, t+delta] > x then set f[x, t+delta] = x
if f[x, t+delta] < 0 then set f[x, t+delta] = 0
end;
end;
If you are not familiar with programming, here is the same thing in the math notation:
$$f(x, 0) := \frac{x^2}{2}$$ $$f'(x, t) := f(x, t) - f(x - \delta_x, t)$$ $$f(x, t + \delta_t) := \min\left(\max\left(\frac{x - f(x, t)}{f'(x,t)} - x, x\right), 0\right)$$
This is the foreign code and it may contain errors. It looks like the method of solving some differential equation using the finite differences, but have only brief knowledge in this field. Thank you in advance!