Hello again everybody,
I’m trying to generate a Vector where which element is a NL expression, here is the code where I’m trying to implement it.
register(rocket2d_hs_2, :StateFunc, 10, StateFunc; autodiff=true)
x_c = Array{AffExpr}(undef,7,n-1)
for j in 1:n-1
for i in 1:7
x_c[i,j] = AffExpr(0.0)
if i<6
val = value(0.5*(X[i,j]+X[i,j+1]) + (Δt/8)*(StateFunc(g_0,c,i,X[:,j]...)-StateFunc(g_0,c,i,X[:,j+1]...)))
else
val = (X[i,j]+X[i,j+1])/2
end
add_to_expression!(x_c[i,j],val)
end
for i in 1:5
@NLconstraints(rocket2d_hs_2,begin
X[i,j+1]-X[i,j] == (Δt/6)*(StateFunc(g_0,c,i,X[:,j]...) + StateFunc(g_0,c,i,x_c[:,j]...) + StateFunc(g_0,c,i,X[:,j+1]...))
end)
end
end
Where X (7xn dim Array) is defined as a @variable and StateFunc is a user.defined function.
I get the following error:
ERROR: MethodError: no method matching /(::NonlinearExpression, ::Int64)
Closest candidates are:
/(::Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8}, ::Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8}) at int.jl:93
/(::StridedArray{P, N} where N, ::Real) where P<:Dates.Period at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\Dates\src\deprecated.jl:44
/(::Union{SparseArrays.SparseVector{Tv, Ti}, SubArray{Tv, 1, var"#s814", Tuple{Base.Slice{Base.OneTo{Int64}}}, false} where var"#s814"<:SparseArrays.AbstractSparseVector{Tv, Ti}, SubArray{Tv, 1, var"#s814", Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, false} where var"#s814"<:SparseArrays.AbstractSparseMatrixCSC{Tv, Ti}} where {Tv, Ti}, ::Number) at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\SparseArrays\src\sparsevector.jl:1450
The error occurs when trying to evaluate “Val =” for the first time.
Maybe I’m not perfectly understanding the syntaxis for an AffExpr Array type given in the documentation. In case it’s not posible, there is another way to do something similar?
Thanks for the help and sorry for any inconvenience!