Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/integral.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Output:
- `unsolved`: the residual unsolved portion of the input
- `err`: the numerical error in reaching the solution
"""
function integrate(eq, x = nothing, domain::Vector{<:Number} = nothing; abstol = 1e-6, num_steps = 2, num_trials = 10,
function integrate(eq, x = nothing, domain::Vector{<:Number} = [NaN]; abstol = 1e-6, num_steps = 2, num_trials = 10,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for safety make it nothing by default.

radius = 1.0,
show_basis = false, opt = STLSQ(exp.(-10:1:0)), bypass = false,
symbolic = true, max_basis = 100, verbose = false, complex_plane = true,
Expand All @@ -73,7 +73,7 @@ function integrate(eq, x = nothing, domain::Vector{<:Number} = nothing; abstol =
s, u, ϵ = integrate_sum(eq, x, l; bypass, abstol, num_trials, num_steps,
radius, show_basis, opt, symbolic,
max_basis, verbose, complex_plane, use_optim)
if domain != nothing
if !all( domain .=== NaN )
s = substitute( s, Dict( [ x=>domain[1] ] ) ) - substitute( s, Dict( [ x=>domain[2] ] ) )
end
# return simplify(s), u, ϵ
Expand Down
19 changes: 19 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,27 @@ function test_integrals(; kw...)
return n
end

function test_definite_integrals()
miss_count = 0
eqn = x
val = SymbolicNumericIntegration.integrate( eqn, x, [ 0, 1 ] )[1]
miss_count += ( isapprox( val, 0.5 ) ) && ( typeof( val ) == typeof( 1 ) )
val = SymbolicNumericIntegration.integrate( eqn, x, [ 0.0, 1.0 ] )[1]
miss_count += ( isapprox( val, 0.5 ) ) && ( typeof( val ) == typeof( 1.0 ) )
val = SymbolicNumericIntegration.integrate( eqn, x, [ 0//1, 1//1 ] )[1]
miss_count += ( isapprox( val, 0.5 ) ) && ( typeof( val ) == typeof( 1//1 ) )
val = SymbolicNumericIntegration.integrate( eqn, x, [ Num(π), Num(2π) ] )[1]
miss_count += ( isequal( val, 3*Num(π)^2/2 ) ) && ( typeof( val ) == typeof( Num(π) ) )
return miss_count
end

@testset "integral" begin
n = test_integrals(; symbolic = false, verbose = false, homotopy = true, num_steps = 2,
num_trials = 10)
@test n > 0
end

@testset "definite_integral" begin
n = test_definite_integrals()
@test n == 0
end