Most books just tells you that spring force is $-kx$ since it opposes motion and to just write $mx''=-kx$ regardless if the spring is in tension of compression.
But when I try to derive this using $F=mx''$ and using free body diagram, and put the mass to the right of the equilibrium position, I get the correct equation of motion, but when the mass is to the left, I do not.
Please tell me what I am doing wrong (and do not just say to use negative sign since it is a restoring force). I need to find the EQM myself from free body diagram.
When the mass to the right we have
x
| |<----->
| | k x (spring force since in tension
|-------------|------<----o mass
| |
| x=0
So applying $F=mx''$ on the above gives $mx''=-kx$ which is the correct EQM. I used minus sign here since the direction of the force vector $kx$ is negative and not because some book said to use negative sign all the time.
Now lets look at it when the mass is to the left and the spring is in compression
x
| <------>
| |
|---->o |
| kx x=0
|
So applying $F=mx''$ gives $mx''=kx$ which is wrong.
The force $kx$ is now in the positive direction. So how to make $kx$ become negative? $x$ is a extension amount. So it is always a positive number as far as finding the force in the spring is concerned. $x$ as a coordinate is negative, yes, but for Hooke's law, force in spring is proportional to extension. Extension is always positive regadless of which way it is.
So when in compression, we have a force pointing in the positive direction and has an amount of $|kx|$. But I need to obtain $mx''=-kx$ even when the spring is in compression. I think my problem is in the $mx''$ term and not in the $kx$ term.
What Am I missing? Where did I go wrong? How to get $mx''=-kx$ when mass to the left using just free body diagram?
adding
This is below is attempt to get the same EQM using D`Alembert's principle. I do not know it well yet, but actually now I get the correct EQM when the spring is in tension or compression using this.
One is supposed to write $F-(mx'')=0$ where now $mx''$ is the so called fictitious inertial force that is always in the opposite direction to the resulting applied forces and acts on the same line.
So using this: When the mass is to the right of the $x=0$ we get $F-(mx'')=0$ or $-kx-(mx'')=0$ or $kx+mx''=0$ so this works ok.
Now lets try it when the mass to the left, we have $F-(-mx'')=0$ where I added a negative sign for $-mx''$ since now it is pointing to the left, i.e. negative. This is because now the force in spring is pointing to the right.
So now we have $kx-(-mx'')=0$ or $kx+mx''=0$ which is the correct EQM !
Is the above correct way of using D`Alembert's principle on this problem?