gusucode.com > 《MATLAB神经网络超级学习手册》随书光盘源码程序 > code/8/N8_4.m

    clear all
clc
x=0.1:0.1:1;
y=[0.3 -0.5 -1 -0.4 -0.9 0.9 -0.3 1.5 0.3 -1.1];
% % 建立BP神经网络及仿真
t1=clock;
net = newff(minmax(x),[10,1],{'tansig' 'purelin'},'trainlm');
net.trainParam.epochs=2000; %网络训练时间设置为2000
net.trainParam.goal=0.01;   %网络训练精度设置为0.5
net=train(net,y,x);        %开始训练网络
data1=etime(clock,t1);      %计算设计网络所用时间
yBp=sim(net,x);            %仿真
figure(1);
plot(x,y,'-',x,yBp, '--')
title('训练后网络的输出结果');
xlabel('时间');
ylabel('仿真输出');

% 建立RBF神经网络及仿真
t2=clock;
net=newrb(x,y,0.1,0.01,20,5);
data2=etime(clock,t2)
yRBF=sim(net,x);            %仿真
figure(2);
plot(x,y,'-',x,yRBF, '--')
title('训练后网络的输出结果');
xlabel('时间');
ylabel('仿真输出');