how to resolve the issue with fmincon

Hi,
I need to use the following code in my program. however, it gives an error and the warning. It happens because I use SIZE() when assigning the initial values. but i must use it that way.
Can someone please help me overcome this?
code:
theta0 = ones(size(svhat),1);
Av = ones(size(svhat),1)';
Av(1,1) = 0;
lbb = zeros(size(svhat),1);
lbb(1,1) = 1;
lbb = eps*lbb;
bv = 0.99999;
opts = optimset('Display','off','Algorithm','sqp');
%function
[theta, opt] = fmincon(@(theta)alach(theta,epshat),theta0,Av,bv,[],[],lbb,[],[],opts);
error:
Warning: Input arguments must be scalar.
> In test at 146
Warning: Input arguments must be scalar.
> In test at 148
Warning: Input arguments must be scalar.
> In test at 151
Error using sqpLineSearch (line 22)
Objective function is undefined at initial point. Fmincon cannot continue.
Error in fmincon (line 851)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = sqpLineSearch(funfcn,X,full(A),full(B),full(Aeq),full(Beq), ...
Error in test (line 161)
[theta, opt] = fmincon(@(theta)alach(theta,epshat),theta0,Av,bv,[],[],lbb,[],[],opts);

 Accepted Answer

Matt J
Matt J on 11 May 2014
Edited: Matt J on 11 May 2014
I think you might really want
theta0 = ones(numel(svhat),1);
or
theta0=ones(size(svhat));
As for the fmincon error, your function @(theta)alach(theta,epshat) is not returning a finite value at theta0. You should check what it is actually returning.

6 Comments

dav
dav on 11 May 2014
Edited: dav on 11 May 2014
thanks.
I am running this in a simulation. so every time the size(svhat) changes. Is that the problem with fmincon
also when I made the change you mentioned it gave me
Error using fmincon (line 300)
A must have 7 column(s).
Error in test (line 161)
[theta, opt] = fmincon(@(theta)alach(theta,epshat),theta0,Av,bv,[],[],lbb,[],[],opts);
I have successfully used this earlier. Can you explain this error please?
dav
We'll know more once you've checked what @(theta)alach(theta,epshat) is returning.
when I made the change you mentioned it gave me
Error using fmincon (line 300) A must have 7 column(s).
Error in test (line 161) [theta, opt] = fmincon(@(theta)alach(theta,epshat),theta0,Av,bv,[],[],lbb,[],[],opts);
I have successfully used this earlier. Can you explain this error please?
Since it doesnt work Im not sure how to get what it returns dav
Execute the following and show the results
fun=@(theta)alach(theta,epshat);
theta0,
ftheta0=fun(theta0),
Av_dims = size(Av),
Do this at the line right before fmincon is called.
dav
dav on 11 May 2014
Edited: dav on 11 May 2014
This is what i got. thanks
theta0 =
1 1 1 1 1 1 1
ftheta0 =
NaN
Av_dims =
7 1
Furthermore, Av should be a row vector while lbb,theta0 are column vectors.
Dear Matt,
The following code worked just fine.
Thank you very much!
code:
theta0 = ones(numel(svhat),1);
Av = ones(numel(svhat),1)';
Av(1,1) = 0;
%Av = Av';
lbb = ones(numel(svhat),1);
lbb(1,1) = 1;
lbb = eps*lbb;
%lbb=lbb';
bv = 0.99999;
opts = optimset('Display','off','Algorithm','sqp');
%function
[theta, opt] = fmincon(@(theta)alach(theta,epshat),theta0,Av,bv,[],[],lbb,[],[],opts);

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Asked:

dav
on 11 May 2014

Commented:

dav
on 11 May 2014

Community Treasure Hunt

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

Start Hunting!