problem with fminunc: why the returned gradient is not a vector

Hi, I am using the fminunc to find a minimum of a multivariable function f(x), where x is a vector. I want to know the value of the gradient at the solution x. So I type "[x,grad] = fminunc(fun,x0)" to get the gradient. However, the returned gradient is a scalar instead of a vector. I think the gradient should be a vector since my x is a vector. Could somebody explain it for me? Thanks!

답변 (1개)

Mischa Kim
Mischa Kim 2014년 3월 4일
편집: Mischa Kim 2014년 3월 4일
Chuoxin, have you set
options = optimset('GradObj','on') % gradient outputted as 2nd argument
or the equivalent through optimoptions (new in R2013a)? If not, the gradient is returned by using
[x,fval,exitflag,output,grad] = fminunc(...) % gradient is 5th argument

댓글 수: 1

The gradient should always be returned in the 5th output argument, even when GradObj option is used.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

태그

질문:

2014년 3월 4일

댓글:

2014년 3월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by