Is an analytic optimization solution possible?

@Frank Kampas posted some code years ago that may help you.

Regards.