math4610

Routine Name: residual

Author: David Merkley

Language: Python

Description/Purpose: finds the residual of an approximation

Input: matrix, vector and vector

Output: the approximation

Implementation/Code:

def residual(A, b, x):
    n = len(b)
    r = [1.0 * ri for ri in b]
    for i in range(n):
        for j in range(n):
            r[i] -= A[i][j] * x[j]
    return r