Skip to content

Commit

Permalink
Merge pull request #52 from JuliaReach/schillic/51
Browse files Browse the repository at this point in the history
#51 - Matrix type not preserved in operations
  • Loading branch information
schillic authored Sep 10, 2019
2 parents 084ce18 + eac69bd commit 535e22b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ of $A$

```jldoctest quickstart
julia> 2A
2×2 Array{Interval{Float64},2}:
2×2 IntervalMatrix{Float64,Interval{Float64},Array{Interval{Float64},2}}:
[0, 2] [2, 4]
[4, 6] [-8, -4]
```
Expand Down Expand Up @@ -78,7 +78,7 @@ $e^{At} - I$. Then, at $t = 1.0$,

```jldoctest quickstart
julia> A + 1/2 * A^2
2×2 Array{Interval{Float64},2}:
2×2 IntervalMatrix{Float64,Interval{Float64},Array{Interval{Float64},2}}:
[1, 4.5] [-3, 2]
[-4, 2.5] [-1, 9]
```
Expand All @@ -88,7 +88,7 @@ in the previous result:

```jldoctest quickstart
julia> quadratic_expansion(A, 1.0)
2×2 Array{Interval{Float64},2}:
2×2 IntervalMatrix{Float64,Interval{Float64},Array{Interval{Float64},2}}:
[1, 4.5] [-2, 1]
[-3, 1.5] [1, 7]
```
Expand Down
3 changes: 3 additions & 0 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ import Base: +, *

*(x::Interval, M::IntervalMatrix) = IntervalMatrix(x .* M.mat)
*(M::IntervalMatrix, x::Interval) = IntervalMatrix(x .* M.mat)

*(x::Number, M::IntervalMatrix) = Interval(x) * M
*(M::IntervalMatrix, x::Number) = Interval(x) * M
2 changes: 1 addition & 1 deletion src/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function quadratic_expansion(A::IntervalMatrix, t)
end
end

W = similar(A)
W = IntervalMatrix(similar(A.mat))

@inbounds for j in 1:n
for i in 1:n
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ end
x = 0.0..2.0
@test x * A == A * x ==
IntervalMatrix([0.0..2.6 0.0..6.8; -2.0..0.0 -0.2..0.2])
# multiply scalar and interval matrix
x = 1.0
for A2 in [x * A, A * x]
@test A2 == A && typeof(A2) == typeof(A)
end
end

@testset "Interval matrix methods" begin
Expand All @@ -39,6 +44,7 @@ end
m = IntervalMatrix([-1.1..0.9 -4.1.. -3.9; 3.9..4.1 -1.1..0.9])
a_over = expm_overapproximation(m, 1.0, 4)
a_under = expm_underapproximation(m, 1.0, 4)
@test a_over isa IntervalMatrix && a_under isa IntervalMatrix
end

@testset "Interval matrix split" begin
Expand Down

0 comments on commit 535e22b

Please sign in to comment.