# Determine the numerical method

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!

-
As this is not a programming site, it may be advisable to leave only the math part of the question and expand it as well. – nbubis Oct 31 '12 at 0:11
What is the context? – Tpofofn Oct 31 '12 at 0:27
@Tpofofn It doesn't have a context. I was asked to translate this pseoudo-code to some programming language, but without understanding the meaning of the function I can't fix some bugs. – Alexander Solovets Oct 31 '12 at 2:11
@nbubis I think that people are unfamiliar with programming will just skip it, but it may help to those who are familiar. Can you give an advice about expanding the math part? – Alexander Solovets Oct 31 '12 at 2:14

$$\partial_t f \cdot \partial_x f + f(1 + \partial_x) = x$$
With the initial condition: $$f(x,t = 0) = x^2/2$$
It moreover looks like the code is neglecting to put in $dx,dt$ when calculating the derivatives.
Thanks! Now it makes much more sense for me. Can you suggest how to set the right values at the boundary: $f'(x,t) := f(x,t) - f(x - \delta_x, t)$ ? Here the left finite difference is used. Can I change it to the right finite difference (i.e. $f(x + \delta_x, t) - f(x, t)$), when $x$ equals $0$? – Alexander Solovets Nov 1 '12 at 5:02