# How to Use SymPy to calculate definite integral for Absolute value function / |x|?

**URL:** https://discourse.julialang.org/t/how-to-use-sympy-to-calculate-definite-integral-for-absolute-value-function-x/91674
**Category:** General Usage
**Tags:** question, package
**Created:** [December 15, 2022, 4:59am UTC](https://discourse.julialang.org/t/how-to-use-sympy-to-calculate-definite-integral-for-absolute-value-function-x/91674 "2022-12-15T04:59:54Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [December 15, 2022, 4:59am UTC](https://discourse.julialang.org/t/how-to-use-sympy-to-calculate-definite-integral-for-absolute-value-function-x/91674/1 "2022-12-15T04:59:55Z")

</div>

Hi all,

another integral problem, I thought this could be done to calculate the simple:

\int\_{-2}^{2} |x| \ dx

with this code:

```julia

x = symbols("x")

f(x) = abs(x)
integrate(f, (x, -2, 2))

```

The errors:

**LoadError: MethodError: no method matching integrate(::typeof(f), ::Tuple{Sym, Int64, Int64})**  
**Closest candidates are:**  
\*\* integrate(::Function) at ~/.julia/packages/SymPy/7cg6m/src/mathfuns.jl:80\*\*  
\*\* integrate(::Function, ::Number, ::Number) at ~/.julia/packages/SymPy/7cg6m/src/mathfuns.jl:76\*\*  
\*\* integrate(::SymPy.SymbolicObject, ::Any…; kwargs…) at ~/.julia/packages/SymPy/7cg6m/src/importexport.jl:102\*\*

---

<div class="post-metadata">

### Author: ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)
#### Post date: [December 15, 2022, 6:51am UTC](https://discourse.julialang.org/t/how-to-use-sympy-to-calculate-definite-integral-for-absolute-value-function-x/91674/2 "2022-12-15T06:51:26Z")

</div>

```julia
x = symbols("x")

f(x) = abs(x)

integrate(f(x), (x, -2, 2))
4

```
