Optimization problem using fminunc

2 Ansichten (letzte 30 Tage)
Hancheng Zhu
Hancheng Zhu am 28 Nov. 2023
Bearbeitet: Dyuman Joshi am 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 Kommentar
Dyuman Joshi
Dyuman Joshi am 28 Nov. 2023
Bearbeitet: Dyuman Joshi am 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

John D'Errico
John D'Errico am 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?

Kategorien

Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by