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

#51 - Matrix type not preserved in operations #52

Merged
merged 3 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
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