Not enough input arguments
2 views (last 30 days)
Show older comments
I am minimizing a function that I created. Getting "Not enough input arguments".
This is the main code:
y=data;
y0=0;
global y y0;
theta0=[0.5, 0.5];
[x,fval,exitflag,output,grad,hessian] = fminunc(condlike,theta0)
This is the function file:
function [ f ] = condlike(x )
Conditional likelihood evaluation for AR(1)
global y y0
[m,n]=size(y);
g = normpdf(y(1,1),x(1)*y0,x(2));
for i=1:n-1
g=g+log(normpdf(y(1,i+1),x(1)*y(1,i),x(2)));
end
f=-g;
end
0 Comments
Accepted Answer
Rik
on 24 Feb 2018
You forgot to make the first input a function handle, using an @ character. The code below ran without errors for me.
data=rand(10,1);
global y y0;
y=data;
y0=0;
theta0=[0.5, 0.5];
[x,fval,exitflag,output,grad,hessian] = fminunc(@condlike,theta0);
function [ f ] = condlike(x )
%Conditional likelihood evaluation for AR(1)
global y y0
[~,n]=size(y);
g = normpdf(y(1,1),x(1)*y0,x(2));
for i=1:n-1
g=g+log(normpdf(y(1,i+1),x(1)*y(1,i),x(2)));
end
f=-g;
end
3 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!