## Critical Points of Multivariable function

### Melissa (view profile)

on 24 May 2011

Hey All, I am currently trying to make a MATLAB program that will find the critical values of a multi-variable function and tell me whether each are a minimum, maximum, or saddle point. I wrote in a function which I know has two critical points but how do I create a loop to where it will calculate all critical points? And how do I actually get the print to show up in the if statements? Here is my current Matlab code:

function [c,d] = critcalpoints(f)

%CRITCALPOINTS(f) is a function to determine the critical points of a 2D

%surface given the function f(x,y).

%The method choosen is to compute the first and second partial derivatives

%on the given function by first evaluating the Jacobian and Hessian Matrix

%and then solve by finding the eigenvalues of obtained critical points.

%Declaration of Variables

syms x y

f=x^3-3*x^2+5*x*y-7*y^2;

% First Order Partial Derivative using the Jacobian Matrix

% Second Order Patrial Derivative using the Hessian Matrix

%Solving the First Order Partial Derivative for critical points

%Evaluating the critical points in the Hessian Matrix

H1=subs(hessmatf,[x,y],[xcr(1),ycr(1)]…

H2=subs(hessmatf,[x,y],[xcr(2),ycr(2)]…

%Computing the eigenvalue of the evaluation of critical points

eig(H1);

eig(H2);

%Converting to numerical values

c = double(eig(H1));

d = double(eig(H2));

%Classifying and Pritning the Critical Points

if (c(1) > 0 & d(1) > 0) | (c(2) > 0 & d(2) > 0)

print( [xcr,ycr], ' is a minimum')

elseif (c(1) < 0 & d(1) < 0) | (c(2) < 0 & d(2) < 0)

print( [xcr, ycr], ' is a maximum')

elseif (c(1) < 0 & d(1) > 0) | (c(1) > 0 & d(1) < 0)

print( [xcr, ycr], ' is a saddle point')

elseif (c(2) < 0 & d(2) > 0) | (c(2) > 0 & d(2) < 0)

print( [xcr, ycr], ' is a saddle point')

elseif (c(1)==0 | d(1)==0)

print( [xcr, ycr], ' is degenerate')

elseif (c(2)==0 | d(2)==0)

print( [xcr, ycr], ' is degenerate')

end

Additional Details In order to obtain critical points it depends on the gradiant, or in this case gradf. So if I wanted to loop it then I would set n=length of gradf? then set a loop 1:n? uh...I dont know if thats correct.

Melissa

### Melissa (view profile)

on 24 May 2011

Ah apparently you cant use sysm in a function, or I did it wrong. Shoot. Help.

## Products

No products are associated with this question.

### bym (view profile)

on 24 May 2011

do you mean

```syms x y   %<-- note you wrote sysm
```

bym

### bym (view profile)

on 24 May 2011

also, I don't know if it will help but take a look at the del2 function

Melissa

### Melissa (view profile)

on 25 May 2011

ah yes I fixed that but still I get errors. thank you though for that catch!