global um r ym s net en1

u=err;
u_h=pi;
u_l=-pi;

%u_max=max(u);
%u_max=min(u_max.*1.5.^sign(u_max),u_h);
u_max=u_h;
%u_min=min(u);
%u_min=max(u_min./1.5.^sign(u_min),u_l);
u_min=u_l;
%um=mean(u);
um=(u_max+u_min)/2;
r=max(u_max-um,um-u_min);
un=(u-meshgrid(um,1:size(u,1)))./meshgrid(r,1:size(u,1));

y=forca;
y_max=150;
%y_max=max(y);
%y_max=y_max.*1.1.^sign(y_max);
y_min=-150;
%y_min=min(y);
%y_min=y_min./1.1.^sign(y_min);
%ym=mean(y);
ym=(y_max+y_min)/2;
s=max(y_max-ym,ym-y_min);
yn=(y-meshgrid(ym,1:size(y,1)))./meshgrid(s,1:size(y,1));

Q=size(u,1);
ui=zeros(Q,2);
ui(1:Q,1)=un(1:(Q));
ui(2:Q,2)=un(1:(Q-1));
%ui=un;

net=newff(ones(2,1)*[-1 1],[5 1],{'tansig','purelin'},'trainbfg');
%net=newff([-1 1],[5 1],{'tansig','purelin'},'trainbfg');
%net.inputWeights{1}.delays=[0 1];
net.trainParam.goal=1e-4;
net=train(net,ui',yn');
%net=train(net,con2seq(ui'),con2seq(yn'));

en1=0;
save nnc um r ym s net en1

ys=sim(net,ui')';
%ys=seq2con(sim(net,con2seq(ui')));
%ys=ys{1}';
plot(t,yn,'.',t,ys);
