# Plot of Cubic Root is not showing the negative f / codomain

**URL:** <https://discourse.julialang.org/t/plot-of-cubic-root-is-not-showing-the-negative-f-codomain/86452>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [August 28, 2022, 7:53am UTC](https://discourse.julialang.org/t/plot-of-cubic-root-is-not-showing-the-negative-f-codomain/86452 "2022-08-28T07:53:50Z")\
**Posts on this page:** 3\
**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:** [August 28, 2022, 7:53am UTC](https://discourse.julialang.org/t/plot-of-cubic-root-is-not-showing-the-negative-f-codomain/86452/1 "2022-08-28T07:53:50Z")

</div>

Hi all,

I want to know why is my Cubic Root graph only showing positive f ?

```julia
using Plots, LaTeXStrings, Plots.PlotMeasures
gr()

f(x) = x^(1/3)  

plot(f,-10,10, xticks=false, xlims=(-13,13), ylims=(-13,13), 
    bottom_margin = 10mm, label=L"f(x) = \sqrt[3]{x}", framestyle = :zerolines, 
    legend=:outerright)

annotate!([(2,0, (L"|", 11, :black))])
annotate!([(8,-3.05, (L"dom(f)=\mathbb{R}", 10, :black))])
annotate!([(8,-4.55, (L"codom(f)=\mathbb{R}", 10, :black))])

```

![Capture d’écran_2022-08-28_14-53-35](https://global.discourse-cdn.com/julialang/original/3X/4/7/470ffd0271e8277804216432f249c5baf05d8b94.png)

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [August 28, 2022, 8:36am UTC](https://discourse.julialang.org/t/plot-of-cubic-root-is-not-showing-the-negative-f-codomain/86452/2 "2022-08-28T08:36:31Z")

</div>

The short answer is to use `cbrt` if you want the real cube root function.

The longer answer is that the general power function only works for negative reals if given as complex numbers and then you get the principal complex branch, which does not follow the negative real axis. Additionally `1/3` is not exactly representable as a binary floating point number, so it’s somewhat unreasonable to expect `x^(1/3)` to act as an ideal cube root.

```julia
julia> (-8)^(1/3)
ERROR: DomainError with -8.0:
Exponentiation yielding a complex result requires a complex argument.
Replace x^y with (x+0im)^y, Complex(x)^y, or similar.
Stacktrace:
 [1] throw_exp_domainerror(x::Float64)
   @ Base.Math ./math.jl:37
 [2] ^
   @ ./math.jl:909 [inlined]
 [3] ^(x::Int64, y::Float64)
   @ Base ./promotion.jl:413
 [4] top-level scope
   @ REPL[273]:1

julia> Complex(-8)^(1/3)
1.0 + 1.7320508075688772im

julia> cbrt(-8)
-2.0

```

---

<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:** [August 28, 2022, 8:42am UTC](https://discourse.julialang.org/t/plot-of-cubic-root-is-not-showing-the-negative-f-codomain/86452/3 "2022-08-28T08:42:18Z")

</div>

Thanks for the long answer, it is really enlightening for me…
