Optimization problem using fminunc

2 次查看(过去 30 天)
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 个评论
Dyuman Joshi
Dyuman Joshi 2023-11-28
编辑:Dyuman Joshi 2023-11-28
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.

请先登录,再进行评论。

回答(1 个)

John D'Errico
John D'Errico 2023-11-28
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?

类别

Help CenterFile Exchange 中查找有关 Linear Least Squares 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by