Vectorize critical points calculation with hessian matrix
Afficher commentaires plus anciens
Hi,
I have a working code to calculate the critical points of a multi-variable function and determine whether the critical points are max, min or saddle. Because I mostly work in R i'm used to vectorize my code but I can't figure out how to vectorize the following (if it's even possible):
% Calculate the symbolic hessian matrix
hessMat = matlabFunction(hessian(f,x));
% First we determine if the hessian matrix on a given set of coordinates is positive
% definite, negative definite or undefinite. And secondly if f attains a
% maximum, minimum or saddle point at the given set of coordinates
for i = 1:length(xcr)
x = xcr(i);
y = ycr(i);
eVal = eig(hessMat(x,y));
if all(eVal>0)
hMsg = 'positive definite';
fMsg = 'local minimum';
elseif all(eVal<0)
hMsg = 'negative definite';
fMsg = 'local maximum';
else
hMsg = 'indefinite';
fMsg = 'saddle point';
end
fprintf('The hessian is %s at (%d,%d), then f attains a %s at (%d,%d).\n',hMsg,x,y,fMsg,x,y);
end
I was thinking of making a multidimensional array of the hessian matrix at the critical points to vectorize the eig(...) but I couldn't figure out how. Is there a function that could help me with this?
Réponses (0)
Catégories
En savoir plus sur Calculus dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!