Anharmonic oscillator solution function I am solving a CLASSICAL an-harmonic oscillator problem with Hamiltonian given by 
$$H= (1/2)\dot{x}^2+(1/2)x^2-(1/2)x^4$$ with all the constants ($k$'s) and mass being taken as 1 (one).
I find that $x= \tanh(t/\sqrt{2})$ is satisfying the equation of motion. 
But my question is how to incorporate the Hamiltonian, $H$ in to this solution so that by providing $H$ we can control the initial conditions of this problem. Or any other solution function that can have $H$ in it.
thanks in advance.
PS= In SHO (m=k=1) lets say $x=A\sin(t)$ then $A= \sqrt{2H}$, where $H$ is the total energy or the Hamiltonian. So $x=\sqrt{H}\sin(t)$.
I need a solution function like this.
 A: Let us do everything in our power to force your function to become a "closed form solution" to this particular problem. For this to happen we must take $x(0)=0$ and $\dot{x}_0=1/\sqrt{2}$. As you rightfully figured out the particle moves in a finite potential well and as such if its initial kinetic energy is small enough it will adopt a bounded trajectory. Unfortunately in order to please you we needed to kick off with an initial velocity that is far to big for the trajectory to be bounded. The particle will therefore run out of the well and then escape to infinity with ever-increasing velocity.
Below is a piece of Mathematica code that does the following. Firstly it solves the equation of motion numerically , secondly it produces the analytical solution and thirdly it also plots your favorite $\tanh(t/\sqrt{2})$ curve.  The first, the second and the third curves are plotted in Purple , Green and Blue respectively. Enjoy:
Clear[x]; t =.;
x[t_] = First[
  x[t] /. NDSolve[{x''[t] == -x[t] + 2 x[t]^3, x[0] == 0, 
     x'[0] == 1/Sqrt[2]}, x[t], {t, -2, 2}]]
t = Range[-2, 2, 1/100];
exSol = Flatten[
   x /. NSolve[  
       Sqrt[1 - I] EllipticF[I ArcSinh[Sqrt[-1 - I] x], -I] == #, 
       x] & /@ t];
ListPlot[Transpose[{t, #}] & /@ {Evaluate[x[t]], exSol, 
   Tanh[t/Sqrt[2]]}, PlotStyle -> {Purple, Green, Blue}, 
 ImageSize :> 800]


As we can see the Purple and the Green curves match perfectly but despite our hard efforts to please you the later curves do not match the Blue one.
Now, how did we get the analytical solution? Since this is a conservative system (with the energy being conserved) the equation of motion always reduces to a first order ODE which in this particular case is separable.
Assume $x_0=0$ and $\dot{x}_0=v$.
Therefore we have:
\begin{eqnarray}
&&\dot{x} = v^2 - x^2 + x^4\\
&&\int\limits_0^x \frac{d\xi}{\sqrt{v^2-\xi^2+\xi^4}} = t\\
-\frac{i \sqrt{\frac{\sqrt{1-4 v^2}-1}{v^2}} F\left(i \sinh ^{-1}\left(\sqrt{2} \sqrt{\frac{1}{\sqrt{1-4 v^2}-1}} x\right)|\frac{1-\sqrt{1-4 v^2}}{\sqrt{1-4 v^2}+1}\right)}{\sqrt{2}} = t
\end{eqnarray}
Here $F(\phi|m)$ is the elliptic integral of the first kind. The way we derived this solution is the following. From the general theory of elliptic integrals we know that antiderivatives of all rational functions involving square roots of polynomials of order four can be reduced to  $F(\phi|m)$, $E(\phi|m)$ and $\Pi(n; \phi|m)$ meaning elliptic integral of the first, of the second and or the third kinds respectively. Rather than presenting the whole theory in here , something that I do not feel myself qualified to do right now, I just used Mathematica to find the antiderivative then simplified the result and checked it and pasted it in here.
The final remark is that if $v<1/2$ the trajectories are bounded orbits and otherwise they are unbounded.
