clc
clear
close all
x1=-1:0.01:1; %生成训练数据x
x2=-1:0.01:1;
[X1,X2]=meshgrid(x1,x2);
yd=sin(pi*X1).*cos(pi*X2);
figure;
mesh(X1,X2,yd);
title('标准sin(pi*x1)*cos(pi*x2)图像');
hold on;
Input=2;
HideLayer=5;
Output=1;
%权值及阈值初始化
w1=rands(HideLayer,Input);%隐含层的权值和阈值
b1=rands(HideLayer,1);
w2=rands(Output,HideLayer);%输出层的权值和阈值
b2=rands(Output,1);
% dw1=zeros(HideLayer,Input);
% dw2=zeros(Output,HideLayer);
error = 0.01;%误差阈值
xite=0.3; %学习速率
M=201;
for m1=1:M
for m2=1:M
y=sin(pi*x1(m1))*cos(pi*x2(m2));
for k=1:50
for i=1:HideLayer%隐层的输出
HOut(i)=logsig(x1(m1)*w1(i,1)+x2(m2