필터 지우기
필터 지우기

Optimization problem using fminunc

조회 수: 3 (최근 30일)
Hancheng Zhu
Hancheng Zhu 2023년 11월 28일
편집: Dyuman Joshi 2023년 11월 28일
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에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by