Integration doesnt work, ndefined function or method 'integral' for input arguments of type 'function_handle'.

Hi to all, I have to solve the following optimization:
theta_cal_const = fmincon(distance , theta0 , [] , [] , [] , [] , lb , ub ,[] ,
options );
with:
distance = @(theta) integral(@(u) integrand(u ,theta),-K, -gap_halfwidth )+ integral(@(u) integrand(u , theta ), gap_halfwidth , K) ;
as a result, matlab returns me the error:
undefined function or method 'integral' for input arguments of type'function_handle'.
Error in ==> fmincon at 517
initVals.f = funfcn{3}(X,varargin{:});
Error in ==> maxLH at 32
theta_cal_const = fmincon(distance , theta0 , [] , [] , [] , [] , lb , ub ,[] ,
options );
Caused by:
Failure in initial user-supplied objective function evaluation. FMINCON cannot
continue.
this is the first time i use fmincon, i dont really understant the error message. Thank you for help

댓글 수: 5

My code is
load returns.TXT;
%%I n i t i a l gues s , parameter s and data ar e de f ined
% NOTE: mu = the ta ( 1 ) ; sigma = the ta ( 2 ) ; lambda = the ta ( 3 ) ; p =theta ( 4 ) ;
% etaPlus = theta ( 5 ) ; etaMinus = the ta ( 6 ) ;
disp ( 'The i n i t i a l gue s s f o r the parameter ve cor i s ( [mu sigmalambda p e taPlus etaMinus ] ) ' ) ;
theta0 = [0.25 0.2 50 0.5 0.05 0.05]; % initial guess for theta
K = 60 ; % +/? K i s the upper / lower i n t e g r a t i o n bound , as byCont & Tankov
gap_halfwidth = 0.02 ; % Hal fwidth o f gap around 0 in the integration interval
stock_prices= returns(:,2);
period_length = round ( length ( stock_prices ) /252) ;
time_resolution = period_length / length(stock_prices ) ;
logreturns = zeros ( length ( stock_prices )-1 ,1) ;
for i =1:( length ( stock_prices )-1)
logreturns ( i ) = log ( stock_prices ( i +1 ,1) / stock_prices( i , 1 ) );
end
sigma_star = std(logreturns ) ;
%%The distance integra1 is defined as a function of theta
integrand = @(u,theta) abs(characteristic_exponent(u,theta)...
-empirica1_characteristic_exponent(u,logreturns,time_resolution)).^2 ...
.*weight (u , sigma_star) ;
distance = @(theta) integral(@(u) integrand(u ,theta),-K, -gap_halfwidth )...
+ integral(@(u) integrand(u,theta), gap_halfwidth , K) ;
%%An opt imi z a t i on r out ine i s used to f i n d the minimizing theta
options = optimset ( 'MaxFunEvals ' , 100000 , 'MaxIter ' ,100000 , 'TolX ' , 1e-6);
lb=[-Inf 0 0 0 0 0 ] ;
ub=[ Inf Inf Inf 1 Inf 0.9999 ] ;
disp ( 'The CONSTRAINED c a l i b r a t i o n r e s u l t i s ( [mu sigma lambda p etaPlus etaMinus ] ) ' ) ;
theta_cal_const = fmincon(distance , theta0 , [] , [] , [] , [] , lb , ub ,[] , options );
disp ( 'The ca libration result is ( [mu sigma lambda p e taPlus etaMinus ] ) ' ) ;
theta_cal = fminsearch ( distance , theta0 ,options )
I formatted your code for you. In future, please use the {}Code button to make it readable.
What do you get when you copy, paste, and run these lines in the Command Window:
a = whos('integral')
b = which('integral')
You should get only:
a =
0x1 struct array with fields:
name
... etc.
b =
C:\Program Files\MATLAB\R2015a\toolbox\matlab\funfun\integral.m
I get a =
0x1 struct array with fields: name size bytes class global sparse complex nesting persistent
b =
''

댓글을 달려면 로그인하십시오.

 채택된 답변

The integral function has been a core MATLAB function since R2012a, so if you have that version or later, you should have it. If your version is earlier than that, use quad or one of its friends instead of integral. (The online documentation is currently for R2015a.)
If you have R2012a or later, you may have a toolbox path problem. See if running these from the Command Window solves it:
restoredefaultpath
rehash toolboxcache

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Scope Variables and Generate Names에 대해 자세히 알아보기

질문:

Dam
2015년 3월 24일

답변:

2015년 3월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by