Clear Filters
Clear Filters

fminunc error message multiple variables

2 views (last 30 days)
Hello everyone!
I want to minimize the following function that I wrote:
function ll = ll_wbl(A, N, Y, X, sum_ll)
%A=theta, A(1)=beta, A(2)=kappa
lambda=exp(X*A(1));
ll=N*log(A(2))+(A(2)-1).*log(Y)-A(2).*log(lambda)-(Y./lambda).^A(2);
ll=-ll;
if sum_ll==true
ll=sum(ll);
end
%grad=sum(Y.*X);
end
over the vector A by using fminunc:
clc; clear;
data = xlsread('ema1996_reduced.xls', 'Sheet1');
UNDUR = data(:,1);
UI = data(:,2);
RR = data(:,3);
RRUI=data(:,4);
DR=data(:,5);
DRUI=data(:,6);
LWAGE=data(:,7);
TENURE=data(:,8);
NONWHITE=data(:,9);
% Store as Y and X matrices
N = size(data, 1);
Y = UNDUR;
X = [ones(N, 1) UI RR RRUI DR DRUI LWAGE TENURE NONWHITE];
A0=zeros(2,1);
% Optmizer settings
options = optimoptions(@fminunc, 'Algorithm', 'quasi-newton');
% Estimate model
[A, fval, exitflag, output ] = fminunc(@ll_wbl, A0, options, Y, X, true);
Unfortunately, this doesn't work out somehow.
I get the following error:
Not enough input arguments.
Error in ll_wbl (line 9)
if sum_ll==true
Error in fminunc (line 278)
f = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial objective function evaluation. FMINUNC cannot continue.
I don't understand what's going on here since I am a newbie. Maybe someone can help me out?
Thanks in advance!

Accepted Answer

Stephan
Stephan on 6 Jan 2019
Hi,
fminunc is only able to pass the optimization variable to the objective function. Since your function needs additionally input arguments, you need to pass them to the objective function.
Read here:
Best regards
Stephan
  12 Comments
mathxaz
mathxaz on 6 Jan 2019
Allright, I see the difference.
Then it might be useful to use sum(sum(ll)) although I still have to think about if it gives me what I want to :)
Thank you so much for your effort!!!
Stephan
Stephan on 6 Jan 2019
please accept useful answers. i wish you success !

Sign in to comment.

More Answers (1)

Stephan
Stephan on 6 Jan 2019

Community Treasure Hunt

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

Start Hunting!