Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP #88 - Symbolic interval matrix power #89

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SymEngine = "123dc426-2d89-5057-bbad-38513e3affd8"
mforets marked this conversation as resolved.
Show resolved Hide resolved

[compat]
julia = "1"
Expand Down
3 changes: 3 additions & 0 deletions src/IntervalMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ using LinearAlgebra
import Random
using Random: AbstractRNG, GLOBAL_RNG, seed!

import SymEngine

using Reexport
@reexport using IntervalArithmetic

Expand All @@ -18,6 +20,7 @@ include("matrix.jl")
# Arithmetic for interval matrices
# =================================
include("arithmetic.jl")
include("power.jl")

# =======================================================
# Methods to handle the exponential of an interval matrix
Expand Down
27 changes: 27 additions & 0 deletions src/power.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Base: ^

function ^(M::IntervalMatrix{T}, k::Integer) where {T}
mforets marked this conversation as resolved.
Show resolved Hide resolved
n = checksquare(M)

# create symbolic matrix
Ms = Matrix{SymEngine.Basic}(undef, n, n)
dict = Dict{SymEngine.Basic, Interval{T}}()
for i in 1:n, j in 1:n
var = SymEngine.symbols("M_$(i)_$(j)")
Ms[i, j] = var
dict[var] = M[i, j]
end

# compute symbolic matrix power
Msᵏ = Ms^k

# substitute intervals in symbolic result
Mᵏ = similar(M)
for i in 1:n, j in 1:n
println(Msᵏ[i, j])
println(dict)
substituted = SymEngine.subs(Msᵏ[i, j], dict)
Mᵏ[i, j] = SymEngine.lambdify(substituted)
end
return Mᵏ
end