Skip to content

Commit ca1a14b

Browse files
committed
add support for definite integration
1 parent ae77a3d commit ca1a14b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/integral.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using LinearAlgebra
22
using Statistics: mean, std
3+
using Symbolics
34

45
Base.signbit(z::Complex{T}) where {T <: Number} = signbit(real(z))
56
Base.signbit(x::SymbolicUtils.Sym{Number}) = false
@@ -21,6 +22,7 @@ Arguments:
2122
----------
2223
- `eq`: a univariate expression
2324
- `x`: the independent variable (optional)
25+
- `domain`: the domain upon which to evaluate a definite integral (optional)
2426
2527
Keyword Arguments:
2628
------------------
@@ -44,7 +46,7 @@ Output:
4446
- `unsolved`: the residual unsolved portion of the input
4547
- `err`: the numerical error in reaching the solution
4648
"""
47-
function integrate(eq, x = nothing; abstol = 1e-6, num_steps = 2, num_trials = 10,
49+
function integrate(eq, x = nothing, domain::Vector{<:Number} = nothing; abstol = 1e-6, num_steps = 2, num_trials = 10,
4850
radius = 1.0,
4951
show_basis = false, opt = STLSQ(exp.(-10:1:0)), bypass = false,
5052
symbolic = true, max_basis = 100, verbose = false, complex_plane = true,
@@ -71,6 +73,9 @@ function integrate(eq, x = nothing; abstol = 1e-6, num_steps = 2, num_trials = 1
7173
s, u, ϵ = integrate_sum(eq, x, l; bypass, abstol, num_trials, num_steps,
7274
radius, show_basis, opt, symbolic,
7375
max_basis, verbose, complex_plane, use_optim)
76+
if domain != nothing
77+
s = substitute( s, Dict( [ x=>domain[1] ] ) ) - substitute( s, Dict( [ x=>domain[2] ] ) )
78+
end
7479
# return simplify(s), u, ϵ
7580
return s, u, ϵ
7681
end

0 commit comments

Comments
 (0)