Note: If abs(x_2[i]) <= eps then the relative error is simply x_1[i].
function AbsRelRMS extends Icons.Function; input Real[:] x_1 "Values of interest" annotation( Dialog(group = "Inputs")); input Real[:] x_2 "Reference values" annotation( Dialog(group = "Inputs")); input Real errorExpected = 1e-6 "if Error_rms < errorExpected then test = Passed"; input Real tolerance = 100*Modelica.Constants.eps "To avoid division by 0"; output Real Error_rms "Root Mean Square error sqrt(sum(Error_abs.^2)/n)"; output Real Error_rmsRel "Root Mean Square error sqrt(sum(Error_rel.^2)/n)"; output Real[size(x_1, 1)] Error_abs "Absolute error (x_1 - x_2)"; output Units.NonDim[size(x_1, 1)] Error_rel "Relative error (x_1 - x_2)/x_2"; output Real passedTest "if 0 (false) then expected and actual values to not match within the expected error"; end AbsRelRMS;