-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Basic integral with equality check * Export integral and add test * Fix Typo * Using Domains for integral * Fix indentation and isequal * Add derivative of integral * Add replaceSym function * Update expand_derivatives for integral and Leibniz rule * Modify expand_derivatives * Remove replaceSym and use substitute instead * Fix typo * Fix typo, change return type to Term * Add tests * Add tests, use istree * Fix isequal , add tests * remove ==true * Add u^2 test * fix test * add istree * fix whitespace Co-authored-by: Christopher Rackauckas <accounts@chrisrackauckas.com>
- Loading branch information
1 parent
9e8facb
commit ed5186b
Showing
5 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# basic integral struct with upper bound and lower bound. | ||
struct Integral{X, T <: Domain} <: Function | ||
x | ||
domain::T | ||
Integral(x,domain) = new{typeof(x),typeof(domain)}(Symbolics.value(x), domain) | ||
end | ||
|
||
(I::Integral)(x) = Term{SymbolicUtils.symtype(x)}(I, [x]) | ||
(I::Integral)(x::Num) = Num(I(Symbolics.value(x))) | ||
SymbolicUtils.promote_symtype(::Integral, x) = x | ||
|
||
function Base.show(io::IO, I::Integral) | ||
print(io, "Integral(", I.x, ", ", I.domain, ")") | ||
end | ||
|
||
Base.:(==)(I1::Integral, I2::Integral) = convert(Bool, simplify(isequal(I1.x, I2.x) && isequal(I1.domain, I2.domain))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Symbolics, Test | ||
using DomainSets | ||
@variables x y | ||
|
||
I1 = Integral(x, ClosedInterval(1, 5)) | ||
I2 = Integral(x, ClosedInterval(1, 5)) | ||
@test I1 == I2 | ||
|
||
@variables v(..) u(..) x y | ||
D = Differential(x) | ||
Dxx = Differential(x)^2 | ||
I = Integral(y, ClosedInterval(1, 5)) | ||
eq = D(I(u(x,y))) ~ 0 | ||
eq_test = I(D(u(x,y))) | ||
@test isequal(expand_derivatives(eq.lhs), Symbolics.value(eq_test)) | ||
|
||
eq = Dxx((I(u(x,y)))) + I(D(u(x,y))) ~ 0 | ||
eq_test = I(D(u(x,y))) + I(D(D(u(x,y)))) | ||
@test isequal(expand_derivatives(eq.lhs), Symbolics.value(eq_test)) | ||
|
||
I = Integral(y, ClosedInterval(1, v(x))) | ||
eq = D((I(u(x,y)))) ~ 0 | ||
eq_test = I(D(u(x,y))) + D(v(x))*u(x, v(x)) | ||
@test isequal(expand_derivatives(eq.lhs), Symbolics.value(eq_test)) | ||
|
||
I = Integral(y, ClosedInterval(1, v(x))) | ||
eq = Dxx((I(u(x,y)))) ~ 0 | ||
eq_test = D(I(D(u(x,y))) + D(v(x))*u(x, v(x))) | ||
eq_test_ = I(D(D(u(x,y)))) + D(D(v(x)))*u(x, v(x)) + 2D(u(x,v(x)))*D(v(x)) | ||
@test isequal(expand_derivatives(eq.lhs), Symbolics.value(eq_test_)) | ||
@test isequal(expand_derivatives(eq.lhs), expand_derivatives(eq_test)) | ||
|
||
eq = D((I(u(x,y)^2))) ~ 0 | ||
eq_test = I(2D(u(x,y))*u(x,y)) + D(v(x))*u(x, v(x))^2 | ||
@test isequal(expand_derivatives(eq.lhs), Symbolics.value(eq_test)) |