Azzera filtri
Azzera filtri

Optimization problem using fminunc

3 visualizzazioni (ultimi 30 giorni)
Hancheng Zhu
Hancheng Zhu il 28 Nov 2023
Modificato: Dyuman Joshi il 28 Nov 2023
I have an optimization problem
where x is a N-dimensional vector need to be optimized and a1,...,a5 are parameters. I have written the objective function as a m.file
f = fun(x,a1,a2,a3,a4,a5).
When I use fminunc(fun,x0,[],a1,a2,a3,a4,a5) to solve this function with initial x=x0, it goes wrong and says "the objective function is undefined at the initial point". I don't know how to solve it.
  1 Commento
Dyuman Joshi
Dyuman Joshi il 28 Nov 2023
Modificato: Dyuman Joshi il 28 Nov 2023
I assume a1, a2, a3, a4 and a5 are numerical parameters. Pass the parameters like this -
f = @(x) fun(x, a1, a2, a3, a4, a5);
sol = fminunc(fun,x0);
In addition to John's answer, I would mention to check if fun() is defined for x=x0.
In case you are using conditions to define the function, there's a chance that fun might not have been defined at all for x=x0.

Accedi per commentare.

Risposte (1)

John D'Errico
John D'Errico il 28 Nov 2023
Apparently, your objective function is not well defined at the initial point. I know, this is a wild guess, but that is exactly what fminunc told you. So what is the problem?
Use a different starting point for the optimization!
It is likely you chose some point where the function returns an inf or NaN. Start it somewhere else. WTP?

Prodotti


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by