Why the integral of |x| is not exact? with SymPy

Dear all,

I have tried SymPy to compute indefinite integral of |x|, this is the code:

using SymPy

# we can also use @vars x y z
x = symbols("x")

but the result is like this at terminal, different from the textbook solution:
Capture d’écran_2022-11-23_20-04-32

Please post code and REPL output as text. And what do include("plot1.jl") and include("plot.jl") have to do with anything?

You need to add an assumption, as is implicit in the textbook:

julia> @syms x y::real
(x, y)

julia> integrate(abs(x),x)
⎮ │x│ dx

julia> integrate(abs(y),y)
⎧  2            
⎪────  for y ≤ 0
⎪ 2             
⎪  2            
⎪ y             
⎪ ──   otherwise
⎩ 2             

1 Like

Thanks a lot! I do not know in Julia code I have to do that… put another line for y

It is testing the code I name it plot.jl, and plot1.jl is for other code. Sorry for the confusion.

The point was to show you needed the assumption (::real did that, though you could do it with keywords to symbols).