diff --git a/src/integral.jl b/src/integral.jl index 04f9d04..3db34da 100644 --- a/src/integral.jl +++ b/src/integral.jl @@ -72,6 +72,11 @@ function integrate(eq, x = nothing; detailed = true) deprecation_warnings(; homotopy, use_optim) + # Check if eq is a vector/array expression and throw an error + if eq isa AbstractArray || eq isa AbstractVector + error("Vector expressions are not supported. Please use element-wise integration with `integrate.([expr1, expr2, ...], x)` instead.") + end + eq = expand(eq) if x == nothing diff --git a/test/runtests.jl b/test/runtests.jl index b4bc8a2..f2c14db 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -327,3 +327,21 @@ end num_trials = 10) @test n > 0 end + +@testset "vector expression error handling" begin + @variables x α + + # Test that vector expressions throw an appropriate error + @test_throws ErrorException("Vector expressions are not supported. Please use element-wise integration with `integrate.([expr1, expr2, ...], x)` instead.") integrate([x]) + @test_throws ErrorException("Vector expressions are not supported. Please use element-wise integration with `integrate.([expr1, expr2, ...], x)` instead.") integrate([1, 2 * α], α) + + # Test that scalar integration still works + @test integrate(x) == ((1//2)*(x^2), 0, 0) + @test integrate(2 * α, α) == (α^2, 0, 0) + + # Test that element-wise integration works + results = integrate.([1, 2 * α], α) + @test length(results) == 2 + @test results[1] == (α, 0, 0) + @test results[2] == (α^2, 0, 0) +end