# Plotting using ImplicitEquations

**URL:** <https://discourse.julialang.org/t/plotting-using-implicitequations/52253>\
**Category:** New to Julia\
**Tags:** plotting\
**Created:** [December 23, 2020, 2:37am UTC](https://discourse.julialang.org/t/plotting-using-implicitequations/52253 "2020-12-23T02:37:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhaveshshrimali](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bhaveshshrimali/32/13233_2.png) [@bhaveshshrimali](https://discourse.julialang.org/u/bhaveshshrimali)\
**Post date:** [December 23, 2020, 2:37am UTC](https://discourse.julialang.org/t/plotting-using-implicitequations/52253/1 "2020-12-23T02:37:15Z")

</div>

[Updated Code]

Hi everyone,

I was trying to use [`ImplicitEquations.jl`](https://github.com/jverzani/ImplicitEquations.jl) to graph some inequalities but I’m not using it properly I guess. Here is a minimal example that I am trying to plot

### Code

```julia
using Plots, LaTeXStrings
using ImplicitEquations
I1 = (λ1, λ2) -> λ1^2 + λ2^2 + 1/(λ2^2 * λ1^2 )
I2 = (λ1, λ2) -> 0.5 * (I1(λ1, λ2)^2 - (λ1^4 + λ2^2 + 1/(λ2^4 * λ1^4 )))
cond1 = (λ1, λ2) -> I2(λ1, λ2)/I1(λ1, λ2) - 0.762 * I1(λ1, λ2) + 9.22 >= 0
cond2 = (λ1, λ2) -> I2(λ1, λ2)/I1(λ1, λ2)^2 + 0.0129 * I1(λ1, λ2) - 0.42 <= 0
cond3 = (λ1, λ2) -> I2(λ1, λ2)/I1(λ1, λ2) - 0.2515 * I1(λ1, λ2) + 0.1477 >= 0

l2l1 = (λ1, λ2) -> λ2 <= λ1
l1l2 = (λ1, λ2) -> λ2 >= λ1^(-0.5)
result = (cond1 ⩵ 0) & (cond2 ⩵ 0) & (l2l1 ⩵ 0) & (l1l2 ⩵ 0) | (cond3 ⩵ 0) # (((cond1 ≥ 0) & (cond2 ≤ 0)) | (cond3 ≥ 0)) & (l2l1 ≤ 0) & (l1l2 ≥ 0)
plot(result, xlims=(1, 6), ylims=(0, 6))

```

### Error

```cpp
ERROR: LoadError: MethodError: no method matching compute(::Array{Any,1}, ::ImplicitEquations.Region, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64)

```

Any hints on what could be going wrong?

### Sympy equivalent (that I am trying to emulate in Julia)

```python3
from sympy import plot_implicit, Symbol, And, Or, Eq

def I1(l1, l2):
    return l1 **2. + l2** 2. + 1./(l1 **2. * l2** 2.)

def I2(l1, l2):
    return 1./2 * (I1(l1, l2) **2. - l1** 4. - l2 **4. - 1./(l1**4. * l2**4.))

# defining the regions in the paper 
def A(l1, l2):
    I1v = I1(l1, l2)
    I2v = I2(l1, l2)
    cond1 = And(I2v/I1v - 0.762*I1v + 9.22 >= 0., I2v/I1v**2 + 0.0129*I1v - 0.42 <= 0.)
    cond2 = I2v/I1v - 0.2515*I1v + 0.1477 >= 0.
    cond3 = Or(cond1, cond2)
    cond_l1_greater_l2 = And(l1 >= l2, cond3)
    cond_l2_greater_l1_half = l2 >= l1**(-0.5)
    
    return And(cond_l1_greater_l2, cond_l2_greater_l1_half)

lmbda1, lmbda2 = Symbol("lambda1", real=True), Symbol("lambda2", real=True)
plot_implicit(A(lmbda1, lmbda2), (lmbda1, 1., 6.), (lmbda2, 0.1, 6.), xlabel=r"$\lambda_1$", ylabel=r"$\lambda_2$", axis_center=(1.0, 0.0), size=(10, 8), backend="matplotlib")

```

which gives the expected result:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/4/c40d2fdc921c748a72313e0fbb68f06cf371c86b.png)

### OS and Julia version

I am on Windows with Julia 1.5 and ImplicitEquations-1.0.3

---

<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 23, 2020, 4:11am UTC](https://discourse.julialang.org/t/plotting-using-implicitequations/52253/2 "2020-12-23T04:11:32Z")

</div>

There is a small bug that is being addressed in v1.0.4 (being tagged now). Until then, the use of

```julia
cond1 = (λ1, λ2) -> I2(λ1, λ2)/I1(λ1, λ2) - 0.762 * I1(λ1, λ2) + 9.22 >= 0

```

and later `cond1 ⩵ 0` should just be:

```julia
cond1 = (λ1, λ2) -> I2(λ1, λ2)/I1(λ1, λ2) - 0.762 * I1(λ1, λ2) + 9.22

```

and then `cond1 ⩵ 0`, as then both `≪` or `≫` would work as you want:

```julia
using Plots, LaTeXStrings
using ImplicitEquations #v1.0.4

I1 = (λ1, λ2) -> λ1^2 + λ2^2 + 1/(λ2^2 * λ1^2 )
I2 = (λ1, λ2) -> 0.5 * (I1(λ1, λ2)^2 - (λ1^4 + λ2^2 + 1/(λ2^4 * λ1^4 )))
cond1 = (λ1, λ2) -> I2(λ1, λ2)/I1(λ1, λ2) - 0.762 * I1(λ1, λ2) + 9.22 
cond2 = (λ1, λ2) -> I2(λ1, λ2)/I1(λ1, λ2)^2 + 0.0129 * I1(λ1, λ2) - 0.42 
cond3 = (λ1, λ2) -> I2(λ1, λ2)/I1(λ1, λ2) - 0.2515 * I1(λ1, λ2) + 0.1477 

l2l1 = (λ1, λ2) -> λ2 - λ1
l1l2 = (λ1, λ2) -> λ2 - λ1^(-0.5)
result = (cond1 ⩵ 0) & (cond2 ⩵ 0) & (l2l1 ⩵ 0) & (l1l2 ⩵ 0) | (cond3 ⩵ 0)
result = (((cond1 ≫ 0) & (cond2 ≪ 0)) | (cond3 ≫ 0)) & (l2l1 ≪ 0) & (l1l2 ≫ 0)
plot(result, xlims=(1, 6), ylims=(0, 6))

```

---

<div class="post-metadata">

**Author:** ![bhaveshshrimali](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bhaveshshrimali/32/13233_2.png) [@bhaveshshrimali](https://discourse.julialang.org/u/bhaveshshrimali)\
**Post date:** [December 23, 2020, 5:12am UTC](https://discourse.julialang.org/t/plotting-using-implicitequations/52253/3 "2020-12-23T05:12:18Z")

</div>

Thanks @j_verzani

Just so that I understand, this is a persistent issue with `1.0.3`, right? Because I remember trying something like what you posted above and it seemed to have failed with the same error message as above.

I can try with `#master` in a bit.

---

<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 23, 2020, 5:54am UTC](https://discourse.julialang.org/t/plotting-using-implicitequations/52253/4 "2020-12-23T05:54:58Z")

</div>

Yes, 1.0.3 had a bug. 1.0.4 should be tagged now.

---

<div class="post-metadata">

**Author:** ![bhaveshshrimali](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bhaveshshrimali/32/13233_2.png) [@bhaveshshrimali](https://discourse.julialang.org/u/bhaveshshrimali)\
**Post date:** [December 23, 2020, 6:00am UTC](https://discourse.julialang.org/t/plotting-using-implicitequations/52253/5 "2020-12-23T06:00:04Z")

</div>

[Update]

Working with `ImplicitEquations#master`. Thanks a lot @j_verzani!!

![regions](https://global.discourse-cdn.com/julialang/original/3X/8/e/8e6dadc4da51583998b34a31232774d22614e27f.png)
