def rrs(ax, b):
r"""
Compute relative residual :math:`\|\mathbf{b} - A \mathbf{x}\|_2 /
\|\mathbf{b}\|_2` of the solution to a linear equation :math:`A \mathbf{x}
= \mathbf{b}`. Returns 1.0 if :math:`\mathbf{b} = 0`.
Parameters
----------
ax : array_like
Linear component :math:`A \mathbf{x}` of equation
b : array_like
Constant component :math:`\mathbf{b}` of equation
Returns
-------
x : float
Relative residual
"""
nrm = linalg.norm(b.ravel())
if nrm == 0.0:
return 1.0
else:
return linalg.norm((ax - b).ravel()) / nrm
评论列表
文章目录