I would like to use Convex.jl to solve a problem along the lines of
using Convex
x = Variable(1)
y = Variable(1)
z = Variable(1)
problem = minimize(x+y+z,norm([x,y,z])<=1)
However, when I run this code, I get the error
MethodError: no method matching AbstractFloat(::Convex.MaxAtom)
Closest candidates are:
(::Type{T})(::AbstractChar) where T<:Union{AbstractChar, Number}
@ Base char.jl:50
(::Type{T})(::Base.TwicePrecision) where T<:Number
@ Base twiceprecision.jl:266
(::Type{T})(::Complex) where T<:Real
@ Base complex.jl:44
...
Stacktrace:
[1] float(x::Convex.MaxAtom)
@ Base ./float.jl:294
[2] generic_normInf(x::Vector{Variable})
@ LinearAlgebra ~/.julia/juliaup/julia-1.9.0-rc2+0.x64.linux.gnu/share/julia/stdlib/v1.9/LinearAlgebra/src/generic.jl:453
[3] normInf
@ ~/.julia/juliaup/julia-1.9.0-rc2+0.x64.linux.gnu/share/julia/stdlib/v1.9/LinearAlgebra/src/generic.jl:527 [inlined]
[4] generic_norm2(x::Vector{Variable})
@ LinearAlgebra ~/.julia/juliaup/julia-1.9.0-rc2+0.x64.linux.gnu/share/julia/stdlib/v1.9/LinearAlgebra/src/generic.jl:463
[5] norm2
@ ~/.julia/juliaup/julia-1.9.0-rc2+0.x64.linux.gnu/share/julia/stdlib/v1.9/LinearAlgebra/src/generic.jl:529 [inlined]
[6] norm(itr::Vector{Variable}, p::Int64)
@ LinearAlgebra ~/.julia/juliaup/julia-1.9.0-rc2+0.x64.linux.gnu/share/julia/stdlib/v1.9/LinearAlgebra/src/generic.jl:598
[7] norm(itr::Vector{Variable})
@ LinearAlgebra ~/.julia/juliaup/julia-1.9.0-rc2+0.x64.linux.gnu/share/julia/stdlib/v1.9/LinearAlgebra/src/generic.jl:596
[8] top-level scope
@ In[9]:5
From this I understand that the norm function can only be used on multi-dimensional variables, not multiple variables. Is there a way to combine multiple one-dimensional variables into a multi-dimensional variable so that this works?
I suppose in principle this is always possible, but it would improve readability etc to be able to use multiple names for conceptually different variables.
I think you might have better luck by defining the vector variable first and then giving individual names to new variables which you constrain to be equal to the vector components?
Thank you! Of course this perfectly answers my question. Thanks also @gdalle ; what you suggest would work as well I think but it is very nice to be able to write things using multiple variables when this is convenient.