Initial conditions
Now let us consider what determines the constants $A$ and $B$, or $a$ and $\Delta$. Of course these are determined by how we start the motion. If we start the motion with just a small displacement, that is one type of oscillation; if we start with an initial displacement and then push up when we let go, we get still a different motion. The constants $A$ and $B$, or $a$ and $\Delta$, or any other way of putting it, are determined, of course, by the way the motion started, not by any other features of the situation. These are called the initial conditions. We would like to connect the initial conditions with the constants. Although this can be done using any one of the forms (21.6), it turns out to be easiest if we use Eq. (21.6c). Suppose that at $t= 0$ we have started with an initial displacement $x_0$ and a certain velocity $v_0$.  This is the most general way we can start the motion. (We cannot specify the acceleration with which it started, true, because that is determined by the spring, once we specify $x_0$.) Now let us calculate $A$ and $B$. We start with the equation for $x$, \begin{equation*} x = A \cos \omega_0t + B \sin \omega_0t. \end{equation*} Since we shall later need the velocity also, we differentiate $x$ and obtain \begin{equation*} v=-\omega_0 A \sin \omega_0t + \omega_0 B \cos \omega_0t. \end{equation*} These expressions are valid for all $t$, but we have special knowledge about $x$ and $v$ at $t= 0$. So if we put $t= 0$ into these equations, on the left we get $x_0$ and $v_0$, because that is what $x$ and $v$ are at $t = 0$; also, we know that the cosine of zero is unity, and the sine of zero is zero. Therefore we get \begin{equation*} x_0=A\cdot 1 + B\cdot 0=A \end{equation*} and \begin{equation*} v_0=-\omega_0 A\cdot 0 + \omega_0 B\cdot 1 = \omega_0 B. \end{equation*} So for this particular case we find that \begin{equation*} A=x_0,\quad B=v_0/\omega_0. \end{equation*}  From these values of $A$ and $B$, we can get $a$ and $\Delta$ if we wish. That is the end of our solution, but there is one physically interesting thing to check, and that is the conservation of energy. Since there are no frictional losses, energy ought to be conserved. Let us use the formula \begin{equation*} x =a\cos\,(\omega_0t+\Delta); \end{equation*} then \begin{equation*} v =-\omega_0 a\sin\,(\omega_0t+\Delta). \end{equation*} Now let us find out what the kinetic energy $T$ is, and what the potential energy $U$ is. The potential energy at any moment is $\tfrac{1}{2}kx^2$, where $x$ is the displacement and $k$ is the constant of the spring. If we substitute for $x$, using our expression above, we get \begin{equation*} U=\tfrac{1}{2}kx^2=\tfrac{1}{2}ka^2\cos^2\,(\omega_0t+\Delta). \end{equation*} Of course the potential energy is not constant; the potential never becomes negative, naturally—there is always some energy in the spring, but the amount of energy fluctuates with $x$. The kinetic energy, on the other hand, is $\tfrac{1}{2}mv^2$, and by substituting for $v$ we get \begin{equation*} T=\tfrac{1}{2}mv^2=\tfrac{1}{2}m\omega_0^2a^2\sin^2\,(\omega_0t+\Delta). \end{equation*} Now the kinetic energy is zero when $x$ is at the maximum, because then there is no velocity; on the other hand, it is maximal when $x$ is passing through zero, because then it is moving fastest. This variation of the kinetic energy is just the opposite of that of the potential energy. But the total energy ought to be a constant. If we note that $k = m\omega_0^2$, we see that  \begin{equation*} T+U=\tfrac{1}{2}m\omega_0^2a^2[\cos^2\,(\omega_0t+\Delta)+ \sin^2\,(\omega_0t+\Delta)]= \tfrac{1}{2}m\omega_0^2a^2. \end{equation*} 
 \begin{align*} T+U &=\tfrac{1}{2}m\omega_0^2a^2[\cos^2\,(\omega_0t+\Delta)+ \sin^2\,(\omega_0t+\Delta)]\\[1.5ex] &= \tfrac{1}{2}m\omega_0^2a^2. \end{align*}  The energy is dependent on the square of the amplitude; if we have twice the amplitude, we get an oscillation which has four times the energy. The average potential energy is half the maximum and, therefore, half the total, and the average kinetic energy is likewise half the total energy.