clear all
close all
clc
numInputs = 5000;
numInputstest = 50;
x1 = 4*(rand(1,numInputs)) - 2;
x2 = 100*(rand(1,numInputs));
x3 = 8*(rand(1,numInputs)) - 5;
y1 = ((5.*(sin(pi.*(x1))) + (20.*(sqrt(x2)))))
y2 = (0.3.*x1.*x2) + (exp(x3))
y3 = (2.*(cos((0.2.*(x2)-2)) + ((x1).*(x3))))
nn = feedforwardnet(200);
nn.trainParam.show = 25;
nn.trainParam.lr = 0.01;
nn.trainParam.mc = 0.9;
nn.trainParam.goal = 0;
nn.trainParam.max_fail = 200;
nn.trainParam.epochs = 1;
nn_untrained = train(nn, [x1; x2; x3], [y1; y2; y3]);
save untrained nn
nn.trainParam.epochs = 2000;
nn_trained = train(nn, [x1; x2; x3], [y1; y2; y3]);
save trained nn
x1t = 4*(rand(1,numInputs)) - 2;
x2t = 100*(rand(1,numInputs));
x3t = 8*(rand(1,numInputs)) - 5;
y1t = (5.*sin(pi.*x1t) + (20.*sqrt(x2t)))
y2t = (0.3.*x1t.*x2t) + (exp(x3t))
y3t = (2.*cos((0.2.*x2t)-2) + (x1t.*x3t))
resultsuntrainedNN = nn_untrained([x1; x2; x3]);
resultsTrainedNN = nn_trained([x1; x2; x3]);
Y1_UntrainedError = y1t - resultsuntrainedNN(1,:);
Y2_UntrainedError = y2t - resultsuntrainedNN(2,:);
Y3_UntrainedError = y3t - resultsuntrainedNN(3,:);
Y1_TrainedError = y1t - resultsTrainedNN(1,:);
Y2_TrainedError = y2t - resultsTrainedNN(2,:);
Y3_TrainedError = y3t - resultsTrainedNN(3,:);
figure(1)
subplot(311); hold on;
title('y1 (Neural Network after 1 epoch)');
plot(y1t,'g-+','LineWidth',0.1); hold on;
plot(resultsuntrainedNN(1,:),'k-o','LineWidth', 0.1); hold off;
legend('predicted Y1', 'actual Y1'); grid;
subplot(312); hold on;
title('y2 (Neural Network 1 epoch)');
plot(y2t,'g-+','LineWidth',0.1); hold on;
plot(resultsuntrainedNN(2,:),'k-o','LineWidth', 0.1); hold off;
legend('predicted Y2', 'actual Y2'); grid;
subplot(313); hold on;
title('y3 (Neural Network 1 epoch)');
plot(y3t,'g-+','LineWidth',0.1); hold on;
plot(resultsuntrainedNN(3,:),'k-o','LineWidth', 0.1); hold off;
legend('predicted Y3', 'actual Y3'); grid;
figure(2)
subplot(311); hold on;
title('y1 (Neural Network after 3000 epochs)');
plot(y1t,'b-+','LineWidth',1); hold on;
plot(resultsTrainedNN(1,:),'k-o','LineWidth', 1); hold off;
legend('predicted Y1', 'actual Y1'); grid;
subplot(312); hold on;
title('y2 (Neural Network after 3000 epochs)');
plot(y2t,'b-+','LineWidth',1); hold on;
plot(resultsTrainedNN(2,:),'k-o','LineWidth', 1); hold off;
legend('predicted Y2', 'actual Y2'); grid;
subplot(313); hold on;
title('y3 (Neural Network after 3000 epochs)');
plot(y3t,'b-+','LineWidth',1); hold on;
plot(resultsTrainedNN(3,:),'k-o','LineWidth', 1); hold off;
legend('predicted Y3', 'actual Y3'); grid;
figure(3)
subplot(311); hold on;
title('Prediction error after 1 epoch)');
plot(Y1_UntrainedError,'k','LineWidth',1); hold on;
plot(Y2_UntrainedError,'r','LineWidth',1); hold on;
plot(Y3_UntrainedError,'g','LineWidth',1); hold off;
legend('Y1 error', 'Y2 error', 'Y3 error'); grid;
subplot(312); hold on;
title('Prediction error after 3000 epochs)');
plot(Y1_TrainedError,'k','LineWidth',1); hold on;
plot(Y2_TrainedError,'r','LineWidth',1); hold on;
plot(Y3_TrainedError,'g','LineWidth',1); hold off;
legend('Y1 error', 'Y2 error', 'Y3 error'); grid;