%% This is created by Jiann-Ming WU
%  All Copyright @  reserved by Jiann-Ming Wu
%  MIT liscense
select=2;
switch select
    case 1
        trainFcn = 'trainlm';
    case 2 
        trainFcn = 'traingd';
end

dim=4;
N=800;
x=rand(N,dim)*2-1;
max_t=1;
t=sin(2*pi*x(:,1)).*x(:,2).^2.*x(:,3).^3.*x(:,4).^4.*exp(-sum(x,2));
net = feedforwardnet(40, 'trainlm');
net = train(net, x', t'/max_t);
y = net(x');

figure
plot(1:length(y),y,'ro');hold on
plot(1:length(y),t,'x');hold on
smse =sqrt(mean((y-t').^2));
fprintf('sqrt of mse = %f\n ',sqrt(mean((y-t').^2)));
