The most straight-forward way to do this is through numerical optimization
Numerical optimization can be as fast as graphical methods and as accurate as analytical methods
R has several functions for optimizing/maximizing functions
Here, we'll use my favorite - nlminb( )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.