# A problem with minimizing a function

I have the following cost function:

$\mbox{BSP Cost}=\sum_{i=1}^{\frac{n}{G}}G^{2}\left\lceil \frac{i}{p}\right\rceil +g\left(p\right)\sum_{i=1}^{\frac{n}{G}}Gi+l\left(p\right)\frac{n}{G}$

I would like to minimize it by choosing an appropriate G (i.e., G is a function of p and n). I have simplified it to the following form:

$\mbox{BSP Cost}=\frac{Gn}{2p}+\frac{n^{2}}{2p}+g\left(p\right)\cdot\left(\frac{n}{2G}+\frac{n^{2}}{2G^{2}}\right)+l\left(p\right)\frac{n}{G}\to\min$

To find the minimization, I used a derivative $\frac{d}{dG}$ on the cost function, and compared to zero. I got this:

$\frac{nG^{3}-g\left(p\right)npG-g\left(p\right)n^{2}p-2l\left(p\right)npG}{2pG^{3}}=0$

$nG^{3}-g\left(p\right)npG-g\left(p\right)np-2l\left(p\right)npG=0$

And I'm not sure how to proceed from this point. Can you help me find a function for G(n,p)? If you see any mistakes in the process above, please tell me.

EDIT: it might also be important to mention that all the variables and functions (g,n,p,l,G) are positive.

EDIT 2: an rough approximation formula will do!

EDIT 3: Here's an approximation of g,l:

$g\left(p\right)=-0.858p^{3}+12.31p^{2}-47.12p+79.67$

$l\left(p\right)=670.9p^{2}+2815p-2763$

-
G is a real? The summation goes up to n/G, which is not an integer. Are we to assume that that means 1 <= i <= n/G ? –  leonbloy Jan 1 '11 at 20:53
Eventually, G will be rounded off to a value that will divide n. Not sure how to put that into the equation. I think your assumption should do that. –  Amir Rachum Jan 1 '11 at 21:02
Why not use Cardano's formula? –  timur Jan 2 '11 at 0:36
Per edit 2: For a rough approximation, it would be useful to know about the relative sizes of p, l(p), and g(p). Do you have any information on this? –  Ross Millikan Jan 2 '11 at 9:37
Per edit 3: For p<1500 or so, G is large compared with 1. The approximation $G=\sqrt{g(p)+2l(p)}$ will be quite accurate. It is derived by ignoring the third term because it is small compared to the second. As I showed in my answer, you can tune that up if you want. –  Ross Millikan Jan 2 '11 at 10:41
Assuming $l(p)$ and $g(p)$ are known, I get the same for the derivative. You can simplifiy it by dividing out $n$. You now have a cubic in $G(n,p)$, though it seems not to be a function of $n$, which can be solved by the usual formula for given n and p, but that is a mess. Alternately, you can write it as $G^2=g(p)p(1+\frac{1}{G})+2l(p)p$ If a numeric solution is acceptable, this should converge nicely-start by evaluating the RHS with $G=0$, find $G^2$, plug $G$ into the RHS and iterate to convergence.