human
I am working on the file "Física Computacional/Ficha 6.ipynb".
The first task is:
Exercício 2 - Método de Jacobi Cíclico
Can you write Python code for it?

Write me a the Python code you requested?
assistant
#Here is the Python code you requested.

def jacobi(A_i, eps, nitmax):
    A = np.copy(A_i)            # para cortar dependências
    m = len(A)
    iteration = 0
    Q = np.identity(m)
    def off(mat):
        off_sum = 0
        for i in range(m):
            for j in range(m):
                if j != i: off_sum += mat[i, j]**2
        return np.sqrt(off_sum)
    def frobenius_norm(mat):
        norm = 0
        for i in range(m):
            for j in range(m):
                norm += mat[i, j]**2
        return np.sqrt(norm)
    while (off(A) > eps and iteration < nitmax):
        j, k, ajk = 0, 0, 0.
        for ji in range(m-1):
            for ki in range(ji+1, m):
                absjk = abs(A[ji, ki])
                if absjk >= ajk:
                    j, k, ajk = ji, ki, absjk
        def CSjk(mati, j, k):
            mat = np.copy(mati)
            if mat[j, j] == mat[k, k]:
                C, S = np.cos(np.pi / 4), np.sin(np.pi / 4)
            else:
                tau = 2*mat[j, k] / (mat[k, k] - mat[j, j])
                chi = 1 / np.sqrt(1 + tau**2)
                C = np.sqrt((1 + chi) / 2)
                S = np.sign(tau) * np.sqrt((1 - chi) / 2)
            return C, S
        C, S = CSjk(A, j, k)
        A_l = np.zeros_like(A)
        for r in range(m):
            if r != j and r != k:
                A_l[r, j] = C * A[r, j] - S * A[r, k]
                A_l[j, r] = C * A[r, j] - S * A[r, k]
                A_l[r, k] = S * A[r, j] + C * A[r, k]
                A_l[k, r] = S * A[r, j] + C * A[r, k]
                for s in range(m):
                    if s != j and s != k:
                        A_l[r, s] = np.copy(A[r, s])

        A_l[j, j] = np.copy((C**2 * A[j, j]) + (S**2 * A[k, k]) - (2 * S * C * A[j, k]))
        A_l[j, k] = S * C * (A[j, j] - A[k, k]) + ((C**2 - S**2) * A[j, k])
        # A_l[j, k] = 0
        A_l[k, j] = np.copy(A_l[j, k])
        A_l[k, k] = np.copy((S**2 * A[j, j]) + (C**2 * A[k, k]) + (2 * S * C * A[j, k]))
        A = A_l
        Q_l = np.zeros_like(Q)
        for r in range(m):
            for s...