"""Literal Python conversion of table3_4.m."""

import numpy as np


def table3_4(n_values=None):
    if n_values is None:
        n = np.array([4, 8, 12, 16, 160], dtype=int)
    else:
        n = np.asarray(n_values, dtype=int)
    N = len(n)
    eM = np.zeros(N)
    for in_ in range(N):
        A = np.zeros((n[in_], n[in_]))
        for i in range(n[in_]):
            a = 1 / (i + 1)
            A[i, 0] = 1
            for j in range(1, n[in_]):
                A[i, j] = a ** j
        xe = np.ones(n[in_])
        b = A @ xe
        xc = np.linalg.solve(A, b)
        r = b - A @ xc
        err = xe - xc
        eM[in_] = np.linalg.norm(err, np.inf)
        # print("\n %d & %17.2e" % (n[in_], eM[in_]), end="")

    print("\n n \t\t  Error", end="")
    for in_ in range(N):
        print("\n %d \t\t  %7.2e" % (n[in_], eM[in_]), end="")
    print()


if __name__ == "__main__":
    table3_4()
