Normwise Relative Error in MATLAB

461 Views Asked by At

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?

1

There are 1 best solutions below

2
On BEST ANSWER

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$.