# Why I can't plot the integral function with SymPy and Plots?

**URL:** <https://discourse.julialang.org/t/why-i-cant-plot-the-integral-function-with-sympy-and-plots/91690>\
**Category:** General Usage\
**Tags:** question, package\
**Created:** [December 15, 2022, 9:55am UTC](https://discourse.julialang.org/t/why-i-cant-plot-the-integral-function-with-sympy-and-plots/91690 "2022-12-15T09:55:48Z")\
**Posts on this page:** 8\
**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, 9:55am UTC](https://discourse.julialang.org/t/why-i-cant-plot-the-integral-function-with-sympy-and-plots/91690/1 "2022-12-15T09:55:48Z")

</div>

Hi all,

I have this simple integral function:

\int (5 + \sin \ x)^{4} \ dx

and I want to plot the integral function above so I use this code:

```julia
using SymPy, Plots

f(x) = integrate((5 + sin(x))^4)

plot(f)

```

but it gets errors:

 ![Capture d’écran_2022-12-15_16-52-53](https://global.discourse-cdn.com/julialang/original/3X/b/e/be3779d22f22c0b2e0550390d09710703fb6db08.png)

I also concern about the Warning when I type `using Plots` why is this occurring? I added today a new package `QuadGK` and maybe that is why…

My package list:

```julia
 Status `~/LasthrimProjection/Project.toml`
  [537997a7] AbstractPlotting v0.18.3
  [6e4b80f9] BenchmarkTools v1.3.2
  [3391f64e] CDDLib v0.7.0
  [13f3f980] CairoMakie v0.5.10
  [5ae59095] Colors v0.12.8
  [39dd38d3] Dierckx v0.5.2
  [b4f34e82] Distances v0.10.7
  [5752ebe1] GMT v0.43.1
  [d997a800] Implicit3DPlotting v0.2.3 `https://github.com/matthiashimmelmann/Implicit3DPlotting.jl.git#main`
  [95701278] ImplicitEquations v1.0.9
  [a98d9a8b] Interpolations v0.14.6
  [d1acc4aa] IntervalArithmetic v0.20.8
  [d8418881] Intervals v1.8.0
  [b964fa9f] LaTeXStrings v1.3.0
  [b4f0291d] LazySets v2.3.0
  [ae8d54c2] Luxor v3.5.0
  [ebaf19f5] MTH229 v0.2.11
  [961ee093] ModelingToolkit v8.11.0
  [429524aa] Optim v1.7.3
  [1dea7af3] OrdinaryDiffEq v6.11.2
  [f0f68f2c] PlotlyJS v0.18.10
  [91a5bcdd] Plots v1.36.0
  [67491407] Polyhedra v0.6.17
  [f27b6e38] Polynomials v3.2.0
  [438e738f] PyCall v1.94.1
  [1fd47b50] QuadGK v2.6.0
  [ce6b1742] RDatasets v0.7.7
  [6e93f119] SchwarzChristoffel v0.1.11
  [24249f21] SymPy v1.1.7
  [78aadeae] SymbolicNumericIntegration v0.8.6
  [9ec6d097] TruthTables v0.4.2
  [e88e6eb3] Zygote v0.6.44
  [de0858da] Printf

```

Thanks

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [December 15, 2022, 10:30am UTC](https://discourse.julialang.org/t/why-i-cant-plot-the-integral-function-with-sympy-and-plots/91690/2 "2022-12-15T10:30:24Z")

</div>

> [@Freya\_the\_Goddess](#):
>
> ```julia
> using SymPy, Plots
> 
> f(x) = integrate((5 + sin(x))^4)
> 
> ```

I don’t think this does what you think it does:

```julia
julia> f(x) = integrate((5 + sin(x))^4)
f (generic function with 1 method)

julia> f(1)
ERROR: MethodError: no method matching integrate(::Float64)

```

when you pass `x`, `(5 + sin(x))^4` is just a nuber - e.g. for `x = pi` you get `5^4 = 625` so you are essentially doing

```julia
julia> integrate(625.0)
ERROR: MethodError: no method matching integrate(::Float64)

```

which doesn’t make a lot of sense. `integrate` is expecting a function rather than a value, so you probably meant:

```julia
julia> g = integrate(y -> (5 + sin(y))^4)
       4 2 2 4
3⋅x⋅sin (x) 3⋅x⋅sin (x)⋅cos (x) 2 3⋅x⋅cos (x) 2
─────────── + ─────────────────── + 75⋅x⋅sin (x) + ─────────── + 75⋅x⋅cos (x)
     8 4 8

               3 3
          5⋅sin (x)⋅cos(x) 2 3⋅sin(x)⋅cos (x)
+ 625⋅x - ──────────────── - 20⋅sin (x)⋅cos(x) - ──────────────── - 75⋅sin(x)⋅
                 8 8

               3
         40⋅cos (x)
cos(x) - ────────── - 500⋅cos(x)

```

Now you can pass a value which will be substituted to derive the integral:

```julia
julia> g(2)
     4 3 3 2 2 4
3⋅cos (2) 3⋅sin(2)⋅cos (2) 5⋅sin (2)⋅cos(2) 3⋅sin (2)⋅cos (2) 3⋅sin (2
───────── - ──────────────── - ──────────────── + ───────────────── + ────────
    4 8 8 2 4

          3
) 40⋅cos (2) 2 2 2
─ - ────────── - 20⋅sin (2)⋅cos(2) + 150⋅cos (2) - 75⋅sin(2)⋅cos(2) + 150⋅sin
        3

(2) - 500⋅cos(2) + 1250

```

---

<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, 10:57am UTC](https://discourse.julialang.org/t/why-i-cant-plot-the-integral-function-with-sympy-and-plots/91690/3 "2022-12-15T10:57:51Z")

</div>

That’s a really clear and easy to understand explanation thanks @nilshg

---

<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, 11:14am UTC](https://discourse.julialang.org/t/why-i-cant-plot-the-integral-function-with-sympy-and-plots/91690/4 "2022-12-15T11:14:17Z")

</div>

Why is the integral calculation for function g that is created from

```julia
g = integrate(y -> (5 + sin(y))^4)

```

different with the function that I input directly:

```julia
julia> integrate(g, 0, 2π)
13824

```

```julia
julia> integrate((5+sin(x))^4, (x, 0, 2pi))
4400.58590951590

```

 ![Capture d’écran_2022-12-15_18-11-54](https://global.discourse-cdn.com/julialang/original/3X/3/0/30e0de7351924d4e09148c2b34625ac3401dab97.png)

---

<div class="post-metadata">

**Author:** ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)\
**Post date:** [December 15, 2022, 11:44am UTC](https://discourse.julialang.org/t/why-i-cant-plot-the-integral-function-with-sympy-and-plots/91690/5 "2022-12-15T11:44:17Z")

</div>

Those are two different functions you are integrating (compare `g` to `(5+sin(x))^4`).

The method `integrate(f::Function, ...)` was intended to be deprecated (which might help clear this up). I’d suggest only integrating symbolic expressions formed directly, as with `(5+sin(x))^4` or through a function, like `f(x)` (not just `f`).

---

<div class="post-metadata">

**Author:** ![JM\_Beckers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jm_beckers/32/22482_2.png) [@JM\_Beckers](https://discourse.julialang.org/u/JM_Beckers)\
**Post date:** [December 15, 2022, 11:44am UTC](https://discourse.julialang.org/t/why-i-cant-plot-the-integral-function-with-sympy-and-plots/91690/6 "2022-12-15T11:44:49Z")

</div>

g is already the integrated function and you do not need to integrate again.

To have the finite integral you want, just use

```julia
g(2pi)-g(0)

```

which yields 4400.5859095159

---

<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, 11:50am UTC](https://discourse.julialang.org/t/why-i-cant-plot-the-integral-function-with-sympy-and-plots/91690/7 "2022-12-15T11:50:24Z")

</div>

Thanks a lot for helping me to understand more.

---

<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, 11:50am UTC](https://discourse.julialang.org/t/why-i-cant-plot-the-integral-function-with-sympy-and-plots/91690/8 "2022-12-15T11:50:50Z")

</div>

Thanks a lot, I think it is clearer now to me.
