(* 二変数関数 f の停留点を求める (よう努力する) *)
kyokuchiten[f_]:=
Module[
{fx,fy},
fx=Simplify[D[f[x,y],x]];
fy=Simplify[D[f[x,y],y]];
Solve[{fx==0,fy==0},{x,y}]
]
(* 二変数関数 f とその停留点のリスト s を分析し、極値の判定をする *)
bunseki[s_,f_]:=
Module[
{ff,HesseXY,aSolution,restSolutions,valf,l1,l2},
ff=f[x,y];
HesseXY = {{D[ff,x,x],D[ff,x,y]},
{D[ff,y,x],D[ff,y,y]}};
restSolutions = s;
While [(restSolutions != {}),
aSolution = First[restSolutions];
restSolutions = Rest[restSolutions];
valf = ff /. aSolution;
{l1,l2} = Eigenvalues[HesseXY /. aSolution];
If [l1 > 0 && l2 > 0,
Print[aSolution, ", 極小 f(x,y)=", valf]];
If [l1 < 0 && l2 < 0,
Print[aSolution, ", 極大 f(x,y)=", valf]];
If [(l1 l2 < 0),
Print[aSolution, ", 極値でない"]];
If [(l1 l2 == 0),
Print[aSolution, ", 極値であるかどうか分からない。"]];
]
]
|