How to make Subscript indices real positive integers or logicals?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I wrote this code in order to create a neural network to approach the function f(x,y,z)=z^2 + x^3 -2xcos(yz+4) within [-1,1].
clc; clear;
x = -1:.01:1;
y = -1:.01:1;
z = -1:.01:1;
f=z.*z + x.*x.*x -2*x.*cos(y.*z +4);
Px=x; Py=y; Pz=z; P={Px;Py;Pz}; T=f;
net=newff([-1 1], [30,30,1], {'tansig','tansig','purelin'},'traingd');
net.trainParam.show = 200;
net.trainParam.lr = 0.01;
net.trainParam.epochs =5000;
net.trainParam.goal = 1e-5;
net.numinputs = 3;
trained = train(net,P, T);
N = 100;
Pxtest = 4*rand(1,N);
Pytest = 4*rand(1,N);
Pztest = 4*rand(1,N);
Ptest=[Pxtest;Pytest;Pztest];
fTest = f(Ptest);
testing= sim(trained,Ptest);
plot(Ptest,atest,'ro', Ptest,fTest,'b*'); grid;
legend('predicted value','actual value')
When I run it, I get the Error :
Subscript indices must either be real positive integers or logicals.
Error in approach_function(line 26)
fTest = f(Ptest);
How can I make that right?
5 Commenti
Rik
il 12 Mag 2021
Modificato: Rik
il 12 Mag 2021
Why do you want to delete the question? If you want private help you should hire a consultant instead of posting on a public forum.
Just so others can still read it after you attempt to delete it:
I wrote this code in order to create a neural network to approach the function f(x,y,z)=z^2 + x^3 -2xcos(yz+4) within [-1,1].
clc; clear;
x = -1:.01:1;
y = -1:.01:1;
z = -1:.01:1;
f=z.*z + x.*x.*x -2*x.*cos(y.*z +4);
Px=x; Py=y; Pz=z; P={Px;Py;Pz}; T=f;
net=newff([-1 1], [30,30,1], {'tansig','tansig','purelin'},'traingd');
net.trainParam.show = 50;
net.trainParam.lr = 0.01;
net.trainParam.epochs =1000;
net.trainParam.goal = 1e-5;
net.numinputs = 3;
%Train
net1 = train(net,P, T);
N = 100;
Pxtest = 4*rand(1,N);
Pytest = 4*rand(1,N);
Pztest = 4*rand(1,N);
Ptest=[Pxtest;Pytest;Pztest];
fTest = f(Ptest);
atest= sim(net1,Ptest);
mse = sum((fTest-atest).^2)/N;
fprintf('Mean square Error = %.4f\n', mse)
% Plot
plot(P,T,'r--',Ptest,atest,'ro', Ptest,fTest,'b*'); grid;
legend('Function','predicted value','actual value')
When I run it, I get the Error :
Subscript indices must either be real positive integers or logicals.
Error in approach_function(line 26)
fTest = f(Ptest);
How can I make that right?
Risposte (1)
Vedere anche
Categorie
Scopri di più su Image Data Workflows in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!