MATLAB: Fminuc error about function evaluation

fminunc

Dear,
I am not able to solve the following Error.
function output=Lobjective(beta1,beta2,beta3,y,alpha)
mu=zeros(size(y,1)+1,1)
sig=zeros(size(y,1)+1,1)
v=zeros(size(y,1),1)
e=zeros(size(y,1),1)
mu(1,1)=y(1,1)
sig(1,1)=0
L=0
for i=1:size(y,1)
mu(i+1,1)=beta1*y(i,1)
a(i,1)=y(i,1)-mu(i,1)
sig(i+1,1)=beta2*a(i,1)^2+beta3*sig(i,1)
v(i,1)=mu(i,1)+norminv(alpha)
e(i,1)=mu(i,1)-normpdf(norminv(alpha))/alpha
L=L-1/(alpha*e(i))*(y(i,1) < v(i,1))*(v(i,1)-y(i,1))+v(i,1)/e(i,1)+log(-e(i,1))-1
end
output=1/size(y,1)*L
end
When I run the following, I get an Error.
alpha=0.05
beta1=3
beta2=0.05
beta3=0.4
options = optimset('LargeScale', 'off');
y=xlsread('C:\Users\Documents\Universiteit 2016-2017\Scriptie\gegevens')
fun=@(beta1,beta2,beta3)Lobjective(beta1,beta2,beta3,alpha,y)
BestInitialCond=[beta1;beta2;beta3]
opt = optimoptions(@fminunc,...
'Algorithm','quasi-newton',...
'HessUpdate','bfgs', ...
'GradObj','on', ...
'FinDiffType','central',...
'DerivativeCheck','on', ...
'Display','iter');
f=@(beta1,beta2,beta3)Lobjective(beta1,beta2,beta3,y,alpha)
fminunc(f,BestInitialCond,opt);
I get the Error:
Not enough input arguments.
Error in @(beta1,beta2,beta3)Lobjective(beta1,beta2,beta3,y,alpha)
Error in fminunc (line 276)
[f,GRAD] = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial objective function evaluation. FMINUNC cannot continue.
And I have no idea why that is. Can you help me please? Thank you so much!

Best Answer

Change to
f=@(beta)Lobjective(beta(1),beta(2),beta(3),y,alpha)
Related Question