Actually, this code fails with an error: Error using zeros Size inputs must be integers. on this line: p=zeros(1,n); The reason is obvious because n is 2.1782 (approximately). to fixed how
h=0.01;t0=0;t1=2.2;n=(t1-t0)/(h+1);p=zeros(1,n);T1=zeros(1,n);x=t0:h:t1;for i=1:nt=(i-1)*h;p(i)=sin(2.5*t.^2-5.*t);T1(i)=(1/3).*sin(2.5*t.^2-5.*t+4.*pi);endP=con2seq(p);T=con2seq(T1);net=newlin([-1,1],1,0,0.1);net.inputweights{1,1}.delays=[1,2,3,4,5];net.inputweights{1,1}.initFcn='rands';net.biases{1}.initFcn='rands';net=init(net);IW=net.IW{1,1};b=net.b{1};net.adaptParam.passes=50;[net,y,E,pf,af]=adapt(net,P(6:n),T(6:n),P(1:5));display(sqrt(mse(E)))view(net)figurehold on;plot(x,cell2mat(T),'b',x(6:end),cell2mat(y),'r'),gridlegend('Reference','output')hold offfigurehold onplot(x(6:end),cell2mat(E),'r'),gridlegend('error')hold off
Best Answer