# Package to integrate ODEsusingDifferentialEquations # Package for Linear Algebra. We will use it to # compute the identiy matrix and other quantities.usingLinearAlgebra# Taken from DifferentialEquations documentation# Take a 4x4 matrixC=Matrix(rand(2,2))A =C -transpose(C) # A is antisymmetricΦ = [1.00.00.01.0] # Initial condition
2×2 Matrix{Float64}:
1.0 0.0
0.0 1.0
# We will now set up the ODE# Define a time interval. It is not necessary # to indicate a set of values where solutions will be# computed.tspan = (0.0,10)f(X,p,t) = A*X # Define the ODE as a simple matrix product.prob =ODEProblem(f,Φ,tspan) # We now set the ODE problemsol =solve(prob) # and use the interface for solutions
# sol is a function which gives the interpolated solutionD=sol(pi/4)transpose(D)*D #D is in SO(2,R)
2×2 Matrix{Float64}:
1.0 0.0
0.0 1.0
# ## Plotting the solutionsusingPlots plot(sol)
# Let us check Liouville theoremdet_of_solution(t)=det(sol(t))plot(det_of_solution,0,10,label="Determinant of Solution")
# #Idea of Geometric integrationTmax=1e3tspan = (0.0,Tmax)prob =ODEProblem(f,Φ,tspan) sol =solve(prob)plot(t->opnorm(sol(t)),0,Tmax, label="Matrix Norm of Solution")
tspan = (0.0,10)f(X,p,t) = A*X # Define the ODE as a simple matrix product.prob =ODEProblem(f,Matrix(I,N,N),tspan) # We now set the ODE problemsol =solve(prob) # and use the interface for solutions