Solution:Generate Training Settraincol1 = linspace(0.1, 15, 40)';eps = (0.2*rand(40,1)) - 0.1;traincol2 = sin(traincol1)./traincol1 - eps;train = [traincol1 traincol2];save('snn_a.txt','train');save('snn_a.mat','train');Generate Test Settestcol1 = linspace(0.1, 15, 400)';eps = (0.2*rand(400,1)) - 0.1;testcol2 = sin(testcol1)./testcol1 - eps;test = [testcol1 testcol2];save('snn_b.txt','test');save('snn_b.mat','test');Training the Neural Networkfunction net = train_net(trainingset, hidden_neurons)    % Parameters:     % train_set:      % labels - y     % hidden_neurons_count:      % Return value:     % net  object representing a neural network    % initialization     % hidden neuron activation function- tanh,     % output neuron activation - linear     net=newff(trainingset(:, 1)', trainingset(:, 2)',hidden_neurons,{'tansig', 'purelin'},'trainlm'); rand('state',sum(100*clock));      %random numbers generator initialization     net=init(net);                     %weights initialization     net.trainParam.goal = 0.01;        %stop- mse criterion     net.trainParam.epochs = 400;       %number of epochs iterations     net=train(net,trainingset(:, 1)', trainingset(:, 2)'); %network training Main Program% input data areaload('snn_a.mat');load('snn_b.mat');hidden_neurons = 4;% net trainingnet = train_net(train, hidden_neurons);% assigning resultsresulttrain = net(train(:, 1)')';resulttest = net(test(:, 1)')';% drawinghold onsn = @(x) sin(x) / x;fplot(sn, [0, 15],'g');plot(train(:, 1), resulttrain, 'r');legend('Original function', ' Result')hold off% print mse resultsmse(net, train(:, 2)', resulttrain')mse(net, test(:, 2)', resulttest')Is this code correctly implemented?Are there any hidden bugs?How can it be improved?
Multi-layered Perceptron
ai;matlab;neural network