Skip to content
DeepForgeby svx
All problems
HardLinear Algebrala-184

Matrix Logarithm Series

Problem

Approximate log(I + A) for a 2x2 matrix A with the truncated Mercator series:

log(I + A) = sum over k = 1..num_terms of (-1)^(k+1) * A^k / k

Return the resulting matrix of floats.

Hint

Maintain the running power T = A^k and alternate the sign each term.

Test cases

case 1
in: [[[0,0],[0,0]],5]
expected: [[0,0],[0,0]]
case 2
in: [[[0,1],[0,0]],5]
expected: [[0,1],[0,0]]
case 3
in: [[[1,0],[0,1]],10]
expected: [[0.6456349206349207,0],[0,0.6456349206349207]]
case 4
in: [[[0,-1],[1,0]],20]
expected: [[0.32281746031746034,-0.7604599047323508],[0.7604599047323508,0.32281746031746034]]
Starter codePython
def matrix_log_series(A, num_terms):
    # Your code here
    pass

4 test cases · run your code against them in the editor