%interpolace 2D funkce v nahodne rozmistenych bodech (x,y)
clear; clc;

N=input('Zadej pocet datovych bodu: ');
X=4*(rand([N 1])-0.5); Y=4*(rand([N 1])-0.5);
Z=X.*Y.*exp(-X.^2-Y.^2);

X2=linspace(-2,2,100); Y2=linspace(-2,2,100);
[X3,Y3]=meshgrid(X2,Y2);

Z4=X3.*Y3.*exp(-X3.^2-Y3.^2);

Z3 = griddata(X,Y,Z,X3,Y3,'cubic');

figure(1)
plot3(X,Y,Z,'.')
title('Puvodni data');

figure(2)
surf(X3,Y3,Z3)
hold on
plot3(X,Y,Z,'r.','MarkerSize',15)
hold off
title('Interpolovana data na zvolene siti bodu');

figure(3)
surf(X3,Y3,Z4)
title('Puvodni funkce na zvolene siti bodu');

delta=Z3-Z4;
figure(4)
colormap(jet)
surf(X3,Y3,delta)
title('Rozdil puvodni funkce a interpolovanych dat na dane siti bodu');
