using LinearAlgebra, PyPlot t = 1 [cosh(t) sinh(t) sinh(t) cosh(t)] exp([0 1; 1 0]*t) t = 20 [cosh(t) sinh(t); sinh(t) cosh(t)] exp([0 1; 1 0]*20) exp(20)/2 * [1 1; 1 1] A = randn(5,5) exp(A) series = I + A # first two terms term = A for n = 2:100 term = term*A / n # compute Aⁿ / n! from the previous term Aⁿ⁻¹/(n-1)! series = series + term end series λ, X = eigen(A) X * Diagonal(exp.(λ)) / X real(X * Diagonal(exp.(λ)) / X) # get rid of tiny imaginary parts B = randn(5,5) exp(A) * exp(B) exp(A + B) exp(A) * exp(2A) exp(3A) exp(2A) * exp(A) inv(exp(A)) exp(-A) C = [ 0 0 1 0 0 0 0 1 -0.02 0.01 0 0 0.01 -0.02 0 0 ] Δt = 1.0 T = exp(C*Δt) # propagator matrix x₀ = [0.0,0,1,0] # initial condition # loop over 300 timesteps and keep track of x₁(t) x = x₀ x₁ = [ x₀[1] ] for i = 1:300 x = T*x # repeatedly multiply by T push!(x₁, x[1]) # & store current x₁(t) in the array x₁ end plot((0:300)*Δt, x₁, "r.-") xlabel("time \$t\$") ylabel("solution \$x_1(t)\$") grid() eigvals(exp(A*Δt)) λ = eigvals(A) exp.(λ * Δt)