# Plotting using ImplicitEquations

[Updated Code]

Hi everyone,

I was trying to use 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

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

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)

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:

### OS and Julia version

I am on Windows with Julia 1.5 and ImplicitEquations-1.0.3

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

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


and later cond1 ⩵ 0 should just be:

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:

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))

5 Likes

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.

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

1 Like

[Update]

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

1 Like