最近小白在學習matlab中遇到了問題,請各位大佬修正指點下。先上代碼!
%code開始
clear all;
clc;
Y0 = [1556.573902;1687.994921;1827.953783;2019.351614;2341.844476;2645.022587;3129.123434;3708.61342;4404.350411;5096.770018;6221.441639;7252.597416;8351.371774;9175.220635;10029.36497;11024.08753;11586.61699;12407.02271;13799.8134;15317.59693];
K0 = [1688.96;1645.64;1619.68;1616.16;1696.87;1765.45;1862.86;1946.95;2054.54;2181.33;2403.98;2767.43;3168.70;3597.55;3962.81;4378.10;4937.75;5370.14;5546.94;5686.01];
L0 = [2025.06;2007.22;2052.48;2177.93;2329.73;2457.29;2600.11;2789.04;3005.94;3224.33;3493.76;3916.50;4006.46;4059.86;4397.80;4532.67;4815.32;5139.09;5357.07;5546.47];
number = 20;
K = K0(1:number);
L = L0(1:number);
P = [K0(1:number),L0(1:number)];P = P';
T = Y0(1:number);T = T';
PR = minmax(P); % value range of P
n = size(T,1); % number of nodes in the output layer
net=newff(PR,[5 n],{'tansig','purelin'});
net.trainParam.epochs = 5000; % maximum number of training cycles
net.trainParam.goal = 0.001; % the target of error
net.trainParam.show=400; % interval number
net=train(net,P,T,[],[],[], 120);
b1 = net.b{1,1}; % threshold of the hidden layer node
b2 = net.b{2,1}; % threshold of the output layer
W1 = net.IW{1,1}; % the link weight between the input layer and the hidden layer
W2 = net.LW{2,1}; % the link weight of the hidden layer and the output layer
y= sim(net,P);
s = number;
b1 = net.b{1,1}; % threshold of the hidden layer node
b1 = repmat(b1,1,s);
b2 = net.b{2,1}; % threshold of the output layer
b2 = repmat(b2,1,s);
Wl=net.IW{1,1}; % the link weight between the input layer and the hidden layer
W2 = net.LW{2,1}; % the link weight of the hidden layer and the output layer
m=net.inputs{1,1}.size; % number of input layer nodes
l=net.layers{1,1}.size; % number of hidden layer nodes
n=net.layers{2,1}.size; % number of output layer nodes
H=Wl*P+b1; % input of hidden layer
Fcn1=net.layers{1}.transferFcn; % hidden layer of the activation function
Hout=feval(Fcn1,H); % output of hidden layer
dFcnl=feval(Fcnl,'deriv');
Fdh=feval(dFcnl,H,Hout); % derivative of the hidden layer activation function with respect to the input h
Y=W2*Hout+b2; % input of output layer
Fcn2=net.layers{2}.transferFcn; % the activation function of the output layer
Yout=feval(Fcn2,Y); % output of output layer
dFcn2=fevaI(Fcn2,'ideriv');
Fdy =feval(dFcn2,Y,Yout); % derivative of the output layer activation function with respect to the input h
Jyh=zeros(n,l,s);
Jhx=zeros(l,m,s);
Jyx=zeros(n,m,s) ;
for u=1:s
Fd1=diag(Fdh(:,u)); % for the u th sample, the derivative of the nonlinear operator with respect to h
Jhx(:,:,u)=Fd1*W1; % for the u th sample, X to h Jacobi matrix
Fd2=diag(Fdy(:,u)); % for the u th sample, derivative of a nonlinear operator with respect to y
Jyh(:,:,u)=Fd2*W2; % for the u th sample, h to y Jacobi matrix
Jyx(:,:,u)=Jyh(:,:,u)*Jhx(:,:,u); % for the u th sample, x to y Jacobi matrix
end
jyx=zeros(s,m);
for u=1:s
jyx(u,:)=Jyx(1,:,u);
end
syx=jyx.*[K;L]./[Y;Y]; % Row u is the elasticity of the output elasticity coefficient to sample u
%code結束

//求助下各位大佬,應該怎么解決這個問題!萬分感謝!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/225675.html
標籤:其他開發語言
