⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nmgenerate1.m

📁 利用神经网络对多项式曲线进行预测
💻 M
字号:
function ft=nmgenerate1(n,m)
n=20;
m=30;
for t=1:n  %generate  the input
     inx(t)=myformula(t/400) ; %the input data of learning % x(1)-x(n)
     outt(t)=t+n;
     outtx(t)=myformula(outt(t)/400); %the learning data %x(n+1)-x(2n)
     b(t)=t+2*n;
     bx(t)=myformula(b(t)/400);
end
P=zeros(n,n);%generate input series
pr=zeros(n,2);%range matrix of input
pr(:,2)=n^2;
P(1,1:n)=inx;%
ps=inx;
t1=outtx;
for s=2:n
 ps(1)=[];
 ps(n)=myformula((s+n-1)/400);
 pj=ps;
P(s,1:n)=pj
s=s+1;
end

net=newff(pr,[m,1],{'tansig','purelin'},'traingdx'); 
net.trainParam.show=50;
net.trainParam.epochs=5000;
net.trainParam.goal=0.00001;
net.trainParam.mc=0.95;
net.trainParam.lr=0.3;
[net,tr]=train(net,P,t1);
a=sim(net,P);
time=1:length(inx);
figure;
plot(time,t1,'--',time,a)
b=reshape(bx,[n,1]);
for k=2:100
    pb(k-1)=sim(net,b); %the  forcasting number
    b(1,:)=[];
    b(n,:)=myformula((k+30)/400);
    c(k-1)=b(n,:); %301-350 for testing
    e(k-1)=(pb(k-1)-c(k-1))*10/c(k-1);
   k=k+1;
end
time2=1:length(pb);
figure;
plot(time2,c,'--',time2,pb)
title('forcasting number and testing number')
figure;
plot(time2,e)
title('the error')


function y=myformula(x)
y=0.5*10*x^2;


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -