MethodError: no method matching ^(::QuadExpr, ::Float64)

I am trying to run this code in Julia but I keep getting this error
MethodError: no method matching ^(::QuadExpr, ::Float64)

below is my code: I will be grateful if someone can help me correct this error. Thanks in advance

using JuMP
using Mosek
using MosekTools
model= Model(Mosek.Optimizer)


#create your variables
@variable(model, x[i=1:NumVar], Bin)
@variable(model, y[i=1:NumVar], Bin)
@variable(model, z[i=1:NumVar], Bin)
@variable(model, r[i=1:NumVar], Bin)
@variable(model, a[i=1:NumVar], Bin)
@variable(model, b[i=1:NumVar], Bin)
@variable(model, X>=0)
@variable(model, Y>=0)
@variable(model, R>=0)

#Define your constraints
for i in 1:NumVar

@constraint(model, x[i] + X  == a[i])
@constraint(model, y[i] + Y  == b[i])
@constraint(model, z[i] + r[i]  == R)
@constraint(model, z[i] >= (x[i]^2 + y[i]^2)^0.5)


#Specify Objective function
@objective(model, Min,R)


@show model
@show termination_status(model)
@show primal_status(model)
@show dual_status(model)
@show objective_value(model)
for i in 1:NumVar
println("x[$i] = ", value(x[i]))
println("y[$i] = ", value(y[i]))
println("z[$i] = ", value(z[i]))
@show value(X)
@show value(Y)

You need to write this as a conic constraint:

@constraint(model, [z[i], x[i], y[i]] in SecondOrderCone())

Thank you for the response.
I did that but this is the output I had


Is this the same as z[i] >= sqrt(x[i]^2 + y[i]^2) where i starts from 1 to 5?

Thus I was expecting an output like

z1>= (x1^2 + y1^2)^0.5
z2>= (x2^2 + y2^2)^0.5
z3>= (x3^2 + y3^2)^0.5
z4>= (x4^2 + y4^2)^0.5
z5>= (x5^2 + y5^2)^0.5

Is the output I had and what I was expecting the same?

It’s the same. See Constraints · JuMP

Thank you very much for the support

1 Like