writing fmincon funtion in matlab

Hi, Can someone please elp me to do the following optimization problem unsin FMINCON . I have a hard time writng the function that is used in FMINCON.
Thanks
clc;
clear;
p=1;
a0 = 0.1; a1 = 0.4;
epsi=zeros(3000,1);
simsig=zeros(3000,1);
for i = 1:3000
if (i==1)
simsig(i) = a0/(1-a1);
s=(simsig(i))^0.5;
epsi(i) = normrnd(0,1) * s;
elseif (i==2)
epsi(i)=epsi(1);
else
simsig(i) = a0+ a1*(epsi(i-1))^2;
s=(simsig(i))^0.5;
epsi(i) = normrnd(0,1) * s;
end
end
yt1=epsi.^2;
ytinitial=yt1(2001:3000);
y=yt1(2001:3000);
len = length(ytinitial);
C = zeros(len,p+1);
C(:,1) = 1; %The first column is for a0
for i = 1:p %Then create shifted columns ( p in number ) for a
C(1+i:len,1+i) = y(1:len-i,1);
end
options =optimset('Display','off','LargeScale','off');
coef = lsqlin(C,ytinitial,[0 1],1,[],[],[0;0],[1;1],[],options);
alpha0 =coef(1);
ar1=coef(2);

 Réponse acceptée

Matt J
Matt J le 19 Mar 2013
Modifié(e) : Matt J le 19 Mar 2013
fun=@(x) norm(C*x(:)-ytinitial)^2;

5 commentaires

dav
dav le 19 Mar 2013
thank you much. Can you please explain why you use : in x(:)
Matt J
Matt J le 19 Mar 2013
To make sure x ends up being a column vector.
dav
dav le 19 Mar 2013
Is the method we use here in fmincon different than the method in lsqlin?
ie. is it worth wwhile to use fmincon instead of lsqlin?
Thanks
Matt J
Matt J le 19 Mar 2013
Modifié(e) : Matt J le 19 Mar 2013
I would expect LSQLIN to perform better than FMINCON, at least in terms of speed, because FMINCON has less knowledge of the problem structure, i.e., it doesn't know the problem is linear least squares.
dav
dav le 19 Mar 2013
thank you very much Matt.

Connectez-vous pour commenter.

Plus de réponses (1)

Alan Weiss
Alan Weiss le 19 Mar 2013

1 vote

Check out the definition of the objective function right at the top of the lsqlin function reference page. This should enable you to write the fmincon equivalent, though I do not know why you would want to do so.
Alan Weiss
MATLAB mathematical toolbox documentation

1 commentaire

dav
dav le 19 Mar 2013
Modifié(e) : dav le 19 Mar 2013
I did but, still couldn't figure it out!
I am having trouble writing the "fun" in x = fmincon(fun,x0,A,b)

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by