Critical Points of Multivariable function

조회 수: 24 (최근 30일)
Melissa
Melissa 2011년 5월 24일
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
gradf = jacobian(f,[x,y]);
% Second Order Patrial Derivative using the Hessian Matrix
hessmatf = jacobian(gradf,[x,y]);
%Solving the First Order Partial Derivative for critical points
[xcr,ycr]=solve(gradf(1),gradf(2));
%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.
  댓글 수: 1
Melissa
Melissa 2011년 5월 24일
Ah apparently you cant use sysm in a function, or I did it wrong. Shoot. Help.

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

답변 (1개)

bym
bym 2011년 5월 24일
do you mean
syms x y %<-- note you wrote sysm
  댓글 수: 2
bym
bym 2011년 5월 24일
also, I don't know if it will help but take a look at the del2 function
Melissa
Melissa 2011년 5월 25일
ah yes I fixed that but still I get errors. thank you though for that catch!

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

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by