The reason behind the discrepancy between the output of the trained neural network and the analytical equation you are using is that the "net” object used by the “fitnet” neural network function in MATLAB uses pre-processing and post-processing functions to process the input and output data. You should add the following lines of code to apply the same process functions:
normalized_x_ref' = mapminmax('apply', x_ref', net.inputs{1}.processSettings{1}); %we are applying the same pre-processing as in the feedforwardnet
y2_ref = mapminmax('reverse', y2_ref, net.outputs{2}.processSettings{1});%we are applying the same post-processing as in the feedforwardnet
Refer to the following documentation page to read more about the process functions:
Additionally, take care of any non-linearity function used before the output layer.