1
$\begingroup$

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?

$\endgroup$
1
  • 1
    $\begingroup$ This question is purely about how to implement something in matlab and should therefore be asked on SO. $\endgroup$
    – P. Siehr
    Oct 25 '17 at 9:28
2
$\begingroup$

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

$\endgroup$
2
  • 1
    $\begingroup$ Small remark, as this might cause confusion: the . is not necessary. $\endgroup$
    – P. Siehr
    Oct 25 '17 at 9:32
  • $\begingroup$ @Harry49 Thank you for your response, this answer has solved my problem. Philipp Siehr: I'm so sorry for wrong categorisation and thanks for your remark! $\endgroup$
    – lynx
    Oct 25 '17 at 10:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.