-
Notifications
You must be signed in to change notification settings - Fork 46
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
Passing parameters and second derivatives #154
Comments
To pass parameters, just use a closure:
NLopt doesn't use second derivatives. |
Thank you. I have changed the now, but I get the same answer as bounds given on the variable. please le know what changes I need to make.?_
|
You are only assigning a single component of (Your code snippet above is not runnable…) |
x is just one variable and not a vector, so there is only one gradient grad[1].
I made few mistakes in copying over the code. Please find the code that reproduces Inf values below. I have also given the equivalent code in JuMP which provides the correct result. These two points are unclear to me: 1. How to specify an equality constraint that requires the value of the function to be zero, when there is just one variable x?
Code in JuMP that works as expected
I also noticed an error in the example given in the documentation here. A variable 'model' is used to define the JuMP Model, but variables and constraints are defined by reference to a variable 'm'.
|
in your first example, so you were optimizing over 2 variables, and both
|
Even if you have only a single variable, |
I'm closing this as it's not an actual issue with NLopt, just a question. |
Thanks. Is there anything in the documentation that explains how to express an objective function that is created by a loop/comprehension such as the code |
You just need to write a Julia function that returns a number. NLopt doesn't need a special form of loop syntax — it is not JuMP. If you want to learn ordinary Julia syntax, see https://julialang.org/learning/
|
Hi there, Thanks for your help. I think there is some misunderstanding. I can write the objective function algebraically, if that is what you are referring to, but I have difficulty in understanding the syntax of inputs required for NLopt. I have defined the objective function and derivatives algebraically, and I replaced In my case there is one variable, so I am not sure the correct way of defining the equality constraint in NLopt. For a two variables function, I can figure out returning from the
|
I also wished the error message was a bit clearer because I stumbled over the same problem as you in the past. As for the rest, it is sufficient to write
When I execute your code, I get |
Thank you! This solves my problem |
@mzaffalon I also noticed that one of the parameters |
I am afraid I cannot help you there. I have never used NLopt |
I have posted this question on Discourse see link here. I am using JuMP for an optimisation problem that uses LD_SLSQP from NLopt. I would like to use NLopt directly rather than calling it from JuMP, but I have not been able to figure out how to do it correctly from the documentation. I have given my code for JuMP and my attempt at implementing in NLopt directly.
The part I find difficult is how to pass on parameters to functions, and first and second derivatives when using NLopt.
Please let me know what corrections I need to make to my code for NLopt?
Runtime code
My attempt at implementing in NLopt directly
The text was updated successfully, but these errors were encountered: