Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot convert an object of type Float64 to an object of type JuMP.NonlinearExpr #3699

Closed
codercahol opened this issue Mar 4, 2024 · 3 comments

Comments

@codercahol
Copy link

I have an array of nonlinear differentials (a, in the example below) that I use as part of an Euler integration step in finding an optimal trajectory. In some cases, one of the differentials is 0, but I haven't been able to figure out how to add it to the vector

Code for reproducing:

a = Vector{NonlinearExpr}(undef, 3)
a = 0.0

I've also tried

a = Vector{NonlinearExpr}(undef, 3)
a[1] = @expression(model, 0.0)

and

a = Vector{NonlinearExpr}(undef, 3)
a[1] = @NLexpression(model, 0.0)

I have it working with a = Vector{Any}, but I expect there is a better solution

@odow
Copy link
Member

odow commented Mar 4, 2024

If you update to JuMP v1.20, the second example works:

julia> model = Model();

julia> a = Vector{NonlinearExpr}(undef, 3)
3-element Vector{NonlinearExpr}:
 #undef
 #undef
 #undef

julia> a[1] = @expression(model, 0.0)
0.0

julia> a
3-element Vector{NonlinearExpr}:
    +(0.0)
 #undef
 #undef

I fixed this a few weeks ago: #3672

But the Vector{Any} is probably a good choice, unless you have evidence showing that it is slow.

p.s., you can ask questions like this on the forum: https://jump.dev/forum

@odow
Copy link
Member

odow commented Mar 4, 2024

Closing as fixed. If you have follow-up questions, please use the forum and we can chat there 😄

@odow odow closed this as completed Mar 4, 2024
@codercahol
Copy link
Author

ok thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants