필터 지우기
필터 지우기

Error in using fmincon to minimization

조회 수: 1 (최근 30일)
Mateusz
Mateusz 2013년 10월 9일
댓글: Mateusz 2013년 10월 10일
Hello!
Below I place fragment of my program:
coef123=stats123.beta %Those are 10 coefficients from my 3-variable equetion
xx1=linspace(-1,1);
xx2=linspace(-1,1);
xx3=linspace(-1,1);
[x1,x2,x3]=meshgrid(xx1,xx2,xx3);
z12=coef123(1)+coef123(2)*x1+coef123(3)*x2+coef123(4)*x3+coef123(5)*x1.*x2+coef123(6)*x1.*x3+coef123(7)*x2.*x3+coef123(8)*x1.^2+coef123(9)*x2.^2+coef123(10)*x3.^2;
xstart=[-1;-1;-1];
[x,fval]=fmincon(@(x)wartoscminimalna,xstart,[],[],[],[],[-1,-1,-1],[1,1,1]);
disp(x)
disp(fval)
Additionally I have function:
function f=wartoscminimalna(x1,x2,x3)
global coef123
f=-(coef123(1)+coef123(2)*x1+coef123(3)*x2+coef123(4)*x3+coef123(5)*x1.*x2+coef123(6)*x1.*x3+coef123(7)*x2.*x3+coef123(8)*x1.^2+coef123(9)*x2.^2+coef123(10)*x3.^2);
Can someone tell me why it doesn't work? I have this kind of error:
Undefined function 'coef123' for input arguments of
type 'double'.
Error in wartoscminimalna (line 2)
f=-(coef123(1)+coef123(2)*x1+coef123(3)*x2+coef123(4)*x3+coef123(5)*x1.*x2+coef123(6)*x1.*x3+coef123(7)*x2.*x3+coef123(8)*x1.^2+coef123(9)*x2.^2+coef123(10)*x3.^2);
Error in @(x1,x2,x3)wartoscminimalna
Error in fmincon (line 601)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in programrstool_4D (line 26)
[x,fval]=fmincon(@(x1,x2,x3)wartoscminimalna,xstart,[],[],[],[],[-1,-1,-1],[1,1,1]);
Caused by:
Failure in initial user-supplied objective
function evaluation. FMINCON cannot continue.
Please help me with it.
Mateusz
  댓글 수: 2
Matt J
Matt J 2013년 10월 9일
Please use the
markup button to put your code in a separate font.
Mateusz
Mateusz 2013년 10월 10일
Sorry for mistake. I've fixed it.

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

채택된 답변

Matt J
Matt J 2013년 10월 10일
편집: Matt J 2013년 10월 10일
Your objective should be implemented as follows
function f=wartoscminimalna(x,coeff123)
x1=x(1);
x2=x(2);
x3=x(3);
f=-(coef123(1)+coef123(2)*x1+coef123(3)*x2+coef123(4)*x3+coef123(5)*x1.*x2+coef123(6)*x1.*x3+coef123(7)*x2.*x3+coef123(8)*x1.^2+coef123(9)*x2.^2+coef123(10)*x3.^2);
and then
[x,fval]=fmincon(@(x)wartoscminimalna(x,stats123.beta),xstart,...
[],[],[],[],[-1,-1,-1],[1,1,1]);
  댓글 수: 1
Mateusz
Mateusz 2013년 10월 10일
편집: Mateusz 2013년 10월 11일
Great!!! You very helped me. Thank you.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by