Using a Morse function to find the number of points of each index During my Algebraic Topology course, we began to talk a bit about Morse functions. I was a bit lost on the topic, and my notes are lacking, so coming across this problem, I'm not really sure what to do:

Consider the sphere $S^2 = \{ (x,y,z) \in \mathbb{R}^3 \mid x^2 + y^2 +z^2 = 1 \}$ and the Morse function $f: S^2 \to \mathbb{R}$ defined by $f(x,y,z) = x^2 + 2y^2 +3z^2$. Find the numbers $a_0, a_1, a_2$ of points of indices $0,1,2$ respectively

I know that $a_0 -a_1 + a_2 = \chi({S^2}) = 2$, but other than that I have no idea how to proceed. My notes seem to indicate that the gradient of some function should be involved somehow, but the gradient of what? $\nabla f$? And even then, I'm not entirely sure what to do with it.
 A: Backing up a moment, let's establish what we're trying to find.  First, we want to find all of the critical points of the function $f$ (restricted to its domain, namely $S^2$).  The statement "$f$ is a Morse function" includes that each critical point is nondegenerate — its second derivative (in the directions tangent to $S^2$) at each critical point should have no kernel.  Then the index of that critical point is the number of negative eigenvalues of the second derivative at that critical point.
Now, $S^2$ is 2-dimensional, so the second derivative at any critical point is a symmetric $2\times 2$ matrix.  So it has two eigenvalues, and hence index $0$ (if both eigenvalues are positive), $1$ (one eigenvalue of each sign), or $2$ (both eigenvalues are negative).  If both eigenvalues of the second derivative are positive at some critical point, then that point is a local minimum; if both are negative, local maximum; mixed is a saddle point.
So now we've translated the problem entirely into geometry.  We have the standard sphere $S^2$, and we want to find: ($0$) the local minima of $f$; ($1$) the saddle points of $f$; ($2$) the local maxima of $f$.
One way to find these is by the method of Lagrange multipliers.  But why work so hard?  You happen to have very nice functions here which we can draw.  So consider a level surface $\{f = c\}$ for various $c\in \mathbb R_{>0}$.  When $c \approx 0$ is very small, the level surface won't touch the sphere; ditto for $c \gg 0$ very large.  As $c$ starts small, eventually the level surface touches the sphere; these points are local minima.  Then it keeps growing.  At the end it clears the sphere at some of the local maxima.  In general, critical points are when some level surface is tangent to the sphere.
What's the geometry of a level surface $\{f=c\}$?  You can read it off: it's an ellipsoid, which is longest in the $x$-direction, shortest in the $z$-direction, and intermediate in the $y$-direction.  (Why?  Calculate the intersections of $\{f=c\}$ with the three axes.)  So the first time $\{f=c\}$ touches the sphere, it does so twice, at the two $x$-direction poles $(\pm 1,0,0)$.  Summarizing earlier remarks, these are some of the critical points of index $0$.
Then the level surface continues to grow, and it intersects the sphere along an oval centered at the $x$-poles.  This ellipse is wider in the $y$-direction than in the $z$-direction.  These two widening ovals eventually meet at the $y$-poles — they haven't grown as fast in the $z$-directions — forming a cross at each pole.  This meeting is indicative of critical points of index $1$ at $(0,\pm 1, 0)$.
After the ovals meet, the level surface continues to grow.  What happens to the intersections?  Near the $y$-poles, it looks like the family of hyperbolas $uv=c$ in the $u,v$ plane: the curves change who connects with whom.  So now there are two ovals centered that the $z$-poles.  They shrink as $c$ grows, eventually to points.  These are the final two critical points: $(0,0,\pm 1)$, of index $2$.  After this, the level surface clears the sphere, and there are no more critical points.
So that's the list of critical points.  Maybe we should confirm that it really is the list.  Claim: If at least two of $x,y,z$ are non-zero, then $(x,y,z)$ is not a critical point.  Proof: Suppose that $x,y\neq 0$.  Then you can increase $x$ by $\epsilon$ and decrease $y$ by $\epsilon x / y$, and up to order $\epsilon^2$ you haven't moved your point off the sphere, but you've changed $f$ by something of order $\epsilon \times (2-1)$.  So it's not a critical point.

The solution to the problem is $(a_0,a_1,a_2)=(2,2,2)$.  But perhaps I should remark that all we used about $\nabla f$ were its zeros (and the Hessians of $f$ at those points).  Morse theory, in the sense of the full Morse complex, requires more from $\nabla f$: an understanding of the gradient flow trajectories.  The notion of "gradient flow" depends on the metric, and for this problem it's convenient to use the round metric, as then you can read off the pertinent gradient flows: they follow the axes.  I mean, the only flows that matter are the ones connecting critical points of adjacent index, and thus they must either start or end at $(0,\pm 1,0)$, and these are just the flows along $x=0$ or along $z=0$.
Thus the Morse complex for this function is, up to some sign convention,
$$ \mathbb Z^2 \overset{\bigl(\begin{smallmatrix} 1 & -1 \\ -1 & 1 \end{smallmatrix} \bigr)} \to \mathbb Z^2 \overset{\bigl(\begin{smallmatrix} 1 & 1 \\ 1 & 1 \end{smallmatrix} \bigr)} \to \mathbb Z^2 $$
in degrees $2$, $1$, and $0$, and so the homology is $(\mathbb Z,0,\mathbb Z)$, as expected.
