How does one apply the phase change of $π$ on reflection at the rigid end of a string? Consider a string, with a free end $P$ and another end $Q$ which is rigidly fixed.
Now, we start oscillating the point $P$ (with $0$ initial phase difference) and a wave starts traveling(in the positive $x$ direction) towards $Q$.  Let us take the equation of this wave to be:
$$y=A\sin(\omega t-kx)$$
where we have taken the origin to lie at the point $P$.
Now, the equation of the reflected wave will be:
$$y=A\sin(\omega t+kx+π)$$
Applying superposition:
$$y=A\sin(\omega t-kx)+A\sin(\omega t+kx+π)=2A\cos\left(kx+\frac{π}{2}\right)\sin\left(\omega t+\frac{π}{2}\right)$$
Now, $y=0$ is required at the end $Q$ of the string for any positive value of $t$. Therefore:
$$\cos\left(kx+\frac{π}{2}\right)=0$$
However, since the length $PQ$ can be any arbitrary length and $y$ will be $=0$ regardless (at $Q$), so $\cos(kx+\frac{π}{2})=0$ should hold for all values of $x$, which is trivially false.
I suspect I have made a mistake in the equation of the reflected wave, and an answer with elaborate detail on how to reflect waves at rigid ends(and free ends also, if possible) would be appreciated. Also, the fact that there is a phase difference of $π$ during reflection at rigid ends is often mentioned, and I would like to how it is to be used.
Note: The question isn't concerned about whether a standing wave is produced or not. We are simply trying to find the equation of reflected wave by using the condition that y=0 at point Q at all times.
 A: The Phet Wave on a string simulation is worth a look at with oscillate chosen.
You can also change the damping, tension, frequency etc to look further at what happens when there is a fixed end.
At the fixed end the reflected wave is $\pi$ out of phase as compared with the incident wave.
The amplitude of the wave at your $x=0$ position is equal to the amplitude of the driver.
In between there is a superposition of two travelling wave moving in opposite directions.
so $\cos(kx+π/2)=0$ should hold for all values of x, which is trivially false.
Not so.
You choose $x$ and the system will "make sure" there is zero amplitude of the string at the position.
A: The general solution to the time-harmonic wave equation on a string may be written as
$$y(x,t)=\sin(\omega t)\left[A\sin(kx) + B\cos(kx)\right].$$
The condition at $x=0$ is that $y(0,t)=A_0\sin(\omega t)$, and so we find that $B=A_0$.  We further require that $y(L,t)=0$, where $L$ is the distance between $P$ and $Q$.  This requirement yields
$$A\sin(kL) + A_0\cos(kL) = 0,$$
or
$$ A = -A_0\frac{\cos(kL)}{\sin(kL)}. $$
The total solution is then given by
$$ y(x,t) = A_0\left[\frac{\sin(\omega t)\cos(kx)\sin(kL)}{\sin(kL)} - \frac{\sin(\omega t)\sin(kx)\cos(kL)}{\sin(kL)}\right]. $$
Using trigonometric identities we may then write
$$y(x,t) = A_0\left[\frac{\cos(\omega t-kx+kL)}{2\sin(kL)} - \frac{\cos(\omega t +kx-kL)}{2\sin(kL)}\right].$$
Notice that the first term in the square brackets represents the forward-propagating wave (from $P$ to $Q$), while the second term represents the backward propagating wave.  Further notice that the two terms have opposite sign when evaluated at $x=L$.  This opposite sign could also be considered a factor of $\cos(\pi)$.  Hence, the reflection at the rigid interface yields a phase factor of $\pi$:
$$y(x,t) = A_0\left[\frac{\cos(\omega t-kx+kL)}{2\sin(kL)} + \frac{\cos(\omega t +kx-kL+\pi)}{2\sin(kL)}\right].$$
