⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hessian.m

📁 计量工具箱
💻 M
字号:
function H = hessian(f,x,varargin)% PURPOSE: Computes finite difference Hessian% -------------------------------------------------------% Usage:  H = hessian(func,x,varargin)% Where: func = function name, fval = func(x,varargin)%           x = vector of parameters (n x 1)%    varargin = optional arguments passed to the function% -------------------------------------------------------% RETURNS:%           H = finite differnce hessian% -------------------------------------------------------% Code from:% COMPECON toolbox [www4.ncsu.edu/~pfackler]% documentation modified to fit the format of the Ecoometrics Toolbox% by James P. LeSage, Dept of Economics% University of Toledo% 2801 W. Bancroft St,% Toledo, OH 43606% jlesage@spatial-econometrics.comeps = 1e-5;n = size(x,1);fx = feval(f,x,varargin{:}); % Compute the stepsize (h)h = eps.^(1/3)*max(abs(x),1e-2);xh = x+h;h = xh-x;    ee = sparse(1:n,1:n,h,n,n); % Compute forward step g = zeros(n,1);for i=1:n  g(i) = feval(f,x+ee(:,i),varargin{:});end   H=h*h';% Compute "double" forward step for i=1:nfor j=i:n  H(i,j) = (feval(f,x+ee(:,i)+ee(:,j),varargin{:})-g(i)-g(j)+fx)/H(i,j);  H(j,i) = H(i,j);endend

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -