I get a problem as $z = \sqrt{x^2 + y^2}$, $x = 1e - 160$, $y = 2e - 160$. It prompts me to think a improved algorithm in Matlab which gives full machine accuracy without using hypot. Can anyone help me with that?
2026-04-03 20:13:15.1775247195
On
how to find full machine error without using hypot in Matlab
47 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
2
There are 2 best solutions below
3
On
Without loss of generality (otherwise use absolute values and/or swap), let $ y \ge x \ge 0$. Then $$z=y \sqrt{ 1 + \left (\frac{x}{y}\right)^2}$$ In your case $$z=2\times 10^{-160}\sqrt{1+(1/2)^2}=2\times 10^{-160}\sqrt{5/4}=\sqrt{5}\times 10^{-160}$$ $$z\approx 2.23606797749979 \times 10^{-160}$$
$$z^2=x^2+y^2=(10^{-160})^2+(2*10^{-160})^2=(10^{-320})+4*(10^{-320})=5*(10^{-320})$$
Thus, taking the square root:
In this way, you can express your result while remaining in the same magnitude ($-160$) as components $x$ and $y$ instead of needing to go down to powers $-320$. In between, you may have the machine epsilon (https://en.wikipedia.org/wiki/Machine_epsilon).