1
$\begingroup$

I like to see a table, what type of points ( Maximum,Sadle, Minimum) , Point and Value of Function shows.

Given a function f:

f = -3*x^2 + x^4 + 3*y + (x*y)/2 - 2*y^3

Plot3D[-3*x^2 + x^4 + 3*y + (x*y)/2 - 2*y^3, {x, -2, 2}, {y, -2, 2}, BoxRatios -> {1, 1, 1}]

  • find the critical points

For critical points we do need first order partial derivatives for x and y. Both must be zero: can be done with a gradient or with partiele derivative for x and y
crPts = NSolve[Grad[f, {x, y}] == {0, 0}, {x, y}]

crtPts2 = NSolve[{D[f, x] == 0 && D[f, y] == 0}, {x, y}]

Note notation : D[f, x] = $\frac{\partial f}{\partial x}$

  • Find the second order partial derivatives( using this for form A1*C1-B1^2) for classifying critical points.

A1 = D[f, x, x]

B1 = D[f, x, y]

C1=D[f, {y, 2}]

  • In a loop, using the quadratic form A1*C1-B1^2, examine each of the 6 critical points:

For k from 1 to 6 do : (there are 6 points, manual counted)

Using crtPts2 : getting a subscript for k

Constructing this loop with some if statements in it, that is the task ?

Output : a table with heading: Type_of_Point, Point, Value_of_Functions

Type_of_Point: Maximum, Saddle, Minimum

Points (critical) : x,y values

Value_of_Function : z-value

$\endgroup$
3
  • $\begingroup$ 1) what have you tried to solve the problem so far? 2) finding a functions critical points is a pretty common problem that has been discussed before on this site. See for instance some do the "Related" questions in the panel on the right on this page. $\endgroup$
    – MarcoB
    Mar 8, 2022 at 13:16
  • $\begingroup$ Indeed finding critical points is not the problem. I want to do the calculation of the critical points with a do loop and present it in a table that is what this question is about. I have studied the Do loop, but an if statement with the table construction is still unknown to me Actually you have to do this in steps. $\endgroup$
    – janhardo
    Mar 8, 2022 at 13:59
  • 1
    $\begingroup$ Typically working in explicit loops is not the most effective way to write Mathematica code. If you have the points already, then please include the code that gave you those points. Generate them in a list (e.g. using Table or Map) and then format them afterwards. The question at the moment sounds like the problem is getting the points, but you seem to say that the problem if formatting them in a table, so clarifications are needed. $\endgroup$
    – MarcoB
    Mar 8, 2022 at 14:46

1 Answer 1

6
$\begingroup$

You seldom need Do loops in MMA. It is better to work with all data at once. In your case:

Critical points:

cps = Solve[Grad[f, {x, y}] == {0, 0}, {x, y}] // N

enter image description here

To determine the type of points we need the second derivatives matrix, the so called Hessian. The eigenvalues of the Hessian determine the type. If they are both positive, it is a maximum, negative, it is a minimum and if they differ it is a saddle;

hes = D[f, {{x, y}, 2}] /. cps;
eig= Eigenvalues /@ hes

enter image description here

With this we create a function that returns the type:

type = Switch[Sign[ #], {1, 1}, "Min", {-1, -1}, 
    "Max", {-1, 1} | {1, -1}, "Saddle"] &;

No we have all the information to create a list or a plot:

TableForm[Table[{type[eig[[i]]], {x, y} /. cps[[i]], f /. cps[[i]]}, {i,6}], TableHeadings -> {None, {"Type", "Point", "Function Value"}}]

enter image description here

Show[Plot3D[f, {x, -2, 2}, {y, -1, 1}]
 , Graphics3D[{PointSize[0.03], Point[{x, y, f} /. cps], 
   MapThread[Text[type[#1], {x, y, 3 + f} /. #2] &, {eig, cps}]}]
 ]

s

$\endgroup$
24
  • $\begingroup$ Thanks. doing this with a determinant : The Hessian, its faster then checking all points one by one : as seen in the in the student's introduction to Mathematica. This calculation of stationary points I also have here also using Maple and there a do loop and if statements were used. In principle I should be able to just translate it to MMA , but it didn't work out very well yet. By the way, I like working with MMA better than Maple with the simpler description of the commands. One thing i like is also a table heading : Type_of_point,Point,Value_of_function $\endgroup$
    – janhardo
    Mar 8, 2022 at 15:35
  • $\begingroup$ I added table headings $\endgroup$ Mar 8, 2022 at 16:36
  • $\begingroup$ Thanks again, It's clearer now what the table stands for. $\endgroup$
    – janhardo
    Mar 8, 2022 at 17:29
  • $\begingroup$ Is it also possible to add a gradientplot to the bottom of the 3D box from Plot3D? $\endgroup$
    – janhardo
    Mar 8, 2022 at 17:56
  • $\begingroup$ VectorPlot[Grad[f, {x, y}], {x, -2, 2}, {y, -1, 1}] $\endgroup$ Mar 8, 2022 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.