% aproximace 1D / MNC
clear; clc;

% data
x = 0:0.3:10; x=x';
z=x.*exp(-x)+0.01*(2*rand(size(x))-1);


% zvolene aproximujici funkce
N=input('Zadej pocet bazovych funkci : ');
for k=1:N
    S=input(['Zadej bazovou funkci S',int2str(k),' : ']);
    G(:,k)=eval(S);
end

c=G\z;

zapprox=0;
for k=1:N
    zapprox=zapprox+c(k)*G(:,k);
end


figure(1)
plot(x,z,'r.')
hold on
plot(x,zapprox,'g-')
hold off



% aproximace polynomem
disp('Aproximace polynomem');
M=input('Zadej stupen polynomu : ');
X = 0:0.1:10;
p = polyfit(x,z,M);
Z = polyval(p,X);

p2 = polyfit(x,z,10);
Z2 = polyval(p,X);


figure(2)
plot(x,z,'o')
hold on
plot(X,Z,'r')
hold on
plot(X,Z2,'g')
hold off







