// Interpolacja 1D
// $$f(x)=∑_{n}α_{n}φ_{n}(x)$$
// $$α_{n}=∫_{R}δ_{n}(x)f(x)dx=f(n)$$
// $$φ_{m}(x)=φ(x-n)$$
function [y] = interpolacja(x, f, fi, R, T)
    r_min = R(1) * T; r_max = R(2) * T; y = 0.0;
 
    for n = r_min:r_max
        alfa_n = f(1/T * n);
        y = y + alfa_n * fi(T * x - n);
    end
endfunction

// Interpolacja 2D
// $$f(x,y)=∑_{n}∑_{m}α_{nm}φ_{nm}(x, y),$$
// $$α_{nm}=∫_{R}∫_{R}δ_{m}(y)f(y)\cdotδ_{n}(x)f(x)dxdy=f(n,m)$$
// $$φ_{nm}(x,y)=φ(x-n)φ(y-m)$$
function [z] = interpolacja2D(_xy_, f2D, fi2D, R, T)
    r_min = R(1) * T; r_max = R(2) * T; z = 0.0;
 
    for n = r_min:r_max
       for m = r_min:r_max
           alfa_nm = f2D(1/T * n, 1/T * m);
           z = z + alfa_nm * fi2D(T * _xy_(1) - n, T * _xy_(2) - m);
       end
    end
endfunction

function [z] = szybsza_interpolacja2D(_xy_, f2D, fi2D, T, r)
    x_min = floor(_xy_(1) * T) - r; x_max = ceil(_xy_(1) * T) + r;
    y_min = floor(_xy_(2) * T) - r; y_max = ceil(_xy_(2) * T) + r;
    z = 0.0;
 
    for n = x_min:x_max
       for m = y_min:y_max
           alfa_nm = f2D(1/T * n, 1/T * m);
           z = z + alfa_nm * fi2D(T * _xy_(1) - n, T * _xy_(2) - m);
       end
    end
endfunction
// Premature optimization is the root of all evil.  (Donald E. Knuth)