Matlab Code for Numerical Hessian Matrix

Matlab code for numerical hessian matrix

In this post, I am sharing a Malab code calculating a numerical hessian matrix. 

You can download here.

You can use NumHessian.m  with this syntax.

function hf = NumHessian(f,x0,varargin)

You can understand how to use simply by reading these two simple examples.

Example 1

>> NumHessian(@cos,0)

ans =

-1.0000

Example 2

function y=test_func(x,a)
y=ax(1)x(2)*x(3);

>> NumHessian(@test_func,[1 2 3]’,2)

ans =

0 6.0000 4.0000
5.9999 -0.0001 1.9998
3.9999 2.0000 0

I hope this Matlab code for numerical Hessian matrix helps your projects

This Matlab code is based on another Matlab function, NumJacob, which calculates a numerical Jacobian matrix. If you are interested in this, visit here.

If you want to know the theory on Hessian matrix, please read this Wiki.

I acknowledge that this code is originally made by Parviz Khavari, a visitor of this blog, and I modified to post here.

 

2 thoughts on “Matlab Code for Numerical Hessian Matrix

    1. admin Post author

      Thanks for the comment. I am also very happy when people get some helps from my blog, and these people sometimes help others. It is so nice experience.

      Reply

Leave a Reply