# Normwise Relative Error in MATLAB [closed]

I have 2 vectors $\textbf{x}$ and $\textbf{y}$. Here, $\textbf{x}$ contains my 'exact' solution data and $\textbf{y}$ is approximated vector. I want to calculate normwise relative error which defined as $E_{r}=\frac{\lVert \textbf{x}-\textbf{y} \rVert_{2}}{\lVert \textbf{y} \rVert_{2}}$. How can I do this in MATLAB?

• This question is purely about how to implement something in matlab and should therefore be asked on SO. Oct 25 '17 at 9:28

If x and y are two Matlab vectors with the same size and y is nonzero, then
Er = norm(x-y)./norm(y)

computes $\|$x$-$y$\|_2/\|$y$\|_2$.
• Small remark, as this might cause confusion: the . is not necessary. Oct 25 '17 at 9:32