Putting constraints for different parts of a matrix using fmincon

조회 수: 1 (최근 30일)
Yagnaseni Roy
Yagnaseni Roy 2014년 4월 13일
댓글: Walter Roberson 2015년 12월 30일
Hi everyone,
So I'm basically using fsolve, and everything's fine with it except that I'm trying to establish limits on a particular segment of the matrix 'x' that fsolve is trying to solve for.
So I put:
lb = -Inf*ones(size(x));
lb(20:22,:) = 0;
x = fmincon(fx,x0,[],[],[],[],lb,[]);
Error returned is:
Error using fmincon (line 713)
User supplied objective function must return a scalar value.
Error in runme (line 25)
x = fmincon(fx,x0,[],[],[],[],lb,[]);
Does anyone know of a way out of this problem? Thanks for the help!
  댓글 수: 2
Matt J
Matt J 2015년 12월 30일
편집: Matt J 2015년 12월 30일
So I'm basically using fsolve, and everything's fine with it except that I'm trying to establish limits on a particular segment of the matrix 'x' that fsolve is trying to solve for.
I think you mean fmincon, not fsolve. That's what your example code shows and that it is a more appropriate tool for problems with bounds.
Error returned is: ... Does anyone know of a way out of this problem? Thanks for the help!
The code you've posted doesn't reveal the root cause of the problem, only that it lies inside fx(). The error message simply means that fx() is not returning a scalar value, as it is expected to.
Walter Roberson
Walter Roberson 2015년 12월 30일
Is your fx a function handle? It is common for people to forget to pass a function handle,
x = fmincon(@fx,x0,[],[],[],[],lb,[]);

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Nonlinear Least Squares (Curve Fitting)에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by