EDIT: Alternative Solution is in a separate post.
This was the first question Berkeley SPS posted last year, and in a manner not dissimilar to them, I finally finished an answer.
A common exercise in both classical EM and Gravitational theories, the question has many formulations; I’ll take the most practical set of quantities relevant to us.
Consider if you have a malleable collection of matter at density ρ, which in its initial spherical shape has a radius a. How can you maximise its gravitational field at one of its poles?
Some considerations follow immediately, and in my working these are not extensively justified.
For example, whatever it is, the desired shape must remain a body of revolution around its central axis, for every slice of it along the central axis should be a circle: any deformations that result in a net nonzero horizontal field is non-optimal.
Secondly, the shape should be “touching” origin, that is, no finite “cut surface” should be near the origin, since a flat surface containing the origin doesn’t contribute to axial gravity.
Thirdly, the far end of the body should contain no flatness either. A quantitative argument is hard, but intuitively, if it did, the same mass that is used to create the smoothness can always be “smooshed” forward to contribute more. Like how initially a sphere is more fit than a cylinder.
Okay…with some mathematical diligence and the blessing of Euler-Lagrange, we shall proceed.
I guess the subtlety is that z_m remains a variable that we are allowed to slide across during the actual variational step … which felt new to me as well.