function [y1] = myNeuralNetworkFunction(x1)
%MYNEURALNETWORKFUNCTION neural network simulation function.
%
% Auto-generated by MATLAB, 09-Jul-2020 12:56:42.
%
% [y1] = myNeuralNetworkFunction(x1) takes these arguments:
%   x = 2xQ matrix, input #1
% and returns:
%   y = 1xQ matrix, output #1
% where Q is the number of samples.

%#ok<*RPMT0>

% ===== NEURAL NETWORK CONSTANTS =====

% Input 1
x1_step1.xoffset = [0;0];
x1_step1.gain = [2;2];
x1_step1.ymin = -1;

% Layer 1
b1 = [-4.4350187667551921322;-3.4425968112041194225;2.4444300804290026718;-1.475520621166917179;-0.50397200024673449725;-0.68837103544559485879;-1.5118827054650509911;2.4718316640481097224;3.4373347693024043359;4.441850705645360442];
IW1_1 = [2.9883593072501404286 -3.2515345241239739238;2.8871744437107631498 3.352829919370826417;-2.7827276971971781627 3.4470926712742624431;4.42465592122861473 -0.15276552406832752395;1.7948113002873888888 4.0419648135414822931;-3.2458135592831545146 -3.004551266406798149;-4.1385094163980697957 -1.5101997518696006484;0.50534433809057910381 4.3870238781330304079;3.737094496856764092 2.3797477907604553948;3.1342311519896890459 3.0977166325174576578];

% Layer 2
b2 = -0.17724670798432698438;
LW2_1 = [0.4064127129585493603 -0.039991107916035814607 0.62656404775561103104 1.252005335760403959 0.74287824959876158637 0.34911043076899961335 0.14372358720278863298 0.12711601270014252774 0.1823687002440615712 -0.80299136554076955274];

% Output 1
y1_step1.ymin = -1;
y1_step1.gain = 2;
y1_step1.xoffset = 0;

% ===== SIMULATION ========

% Dimensions
Q = size(x1,2); % samples

% Input 1
xp1 = mapminmax_apply(x1,x1_step1);

% Layer 1
a1 = tansig_apply(repmat(b1,1,Q) + IW1_1*xp1);

% Layer 2
a2 = repmat(b2,1,Q) + LW2_1*a1;

% Output 1
y1 = mapminmax_reverse(a2,y1_step1);
end

% ===== MODULE FUNCTIONS ========

% Map Minimum and Maximum Input Processing Function
function y = mapminmax_apply(x,settings)
y = bsxfun(@minus,x,settings.xoffset);
y = bsxfun(@times,y,settings.gain);
y = bsxfun(@plus,y,settings.ymin);
end

% Sigmoid Symmetric Transfer Function
function a = tansig_apply(n,~)
a = 2 ./ (1 + exp(-2*n)) - 1;
end

% Map Minimum and Maximum Output Reverse-Processing Function
function x = mapminmax_reverse(y,settings)
x = bsxfun(@minus,y,settings.ymin);
x = bsxfun(@rdivide,x,settings.gain);
x = bsxfun(@plus,x,settings.xoffset);
end
