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$


Solution 1:

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.