All problems
Matrix Exponential via Series
Problem
Approximate the matrix exponential of a 2x2 matrix A with a truncated power series including terms k = 0 through num_terms - 1:
exp(A) = sum over k of A^k / k!
Return the resulting matrix of floats.
Hint
Keep the current term T = A^k / k! and update T = (T*A)/k each step.
Test cases
case 1
in: [[[0,0],[0,0]],5]
expected: [[1,0],[0,1]]
case 2
in: [[[0,1],[0,0]],5]
expected: [[1,1],[0,1]]
case 3
in: [[[1,0],[0,1]],10]
expected: [[2.7182815255731922,0],[0,2.7182815255731922]]
case 4
in: [[[0,-1],[1,0]],20]
expected: [[0.5403023058681397,-0.8414709848078965],[0.8414709848078965,0.5403023058681397]]
Starter codePython
def matrix_exponential(A, num_terms):
# Your code here
pass4 test cases · run your code against them in the editor