where did I lose the negative sign when spring is in compression in a mass-spring problem?

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?

This is below is attempt to get the same EQM using DAlembert'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 DAlembert's principle on this problem?

-

I am just repeating what everyone has said here, but hopefully this will make it clearer.

What you are doing is conflating $x$ as a coordinate and as a distance. When we use Newton's laws $F = m \ddot{x}$, $x$ is a coordinate.

Let's set up the scenario more carefully than you have done. Let's have a coordinate system where rightwards is positive. Say we have a spring of unstretched length $l$ (this is a distance, not a coordinate). Fix one end of the spring be at coordinate $0$, and let the free end be at coordinate $l$ initially.

Now we consider perturbations about this equilibrium configuration. Define $x$ to be the displacement of the free end from coordinate $l$, so that the coordinate of the free end is now given by $y = l + x$ (it is a function of time). Note that $x$ is not the extension amount. The extension amount is instead $|x|$.

Now we can do what you did, consider the two cases. When the spring is extended, that is, when $x > 0$, we have from Newton's 2nd law: \begin{align} m \ddot{y} = -k|x|. \end{align} Ok let's pause to see what I've written here. the LHS is the 2nd time derivative of the coordinate of the free end of the spring (with a mass attached to it). The right hand side is the sum of forces, which by Hooke's law has magnitude $k|x|$ and I have thrown in the minus sign because it points to the left.

But note that $\ddot{y} = \ddot{(l + x)} = \ddot{x}$ since $l$ is a constant. Also, since $x > 0$, $|x| = x$. So we get \begin{align} m\ddot{x} = -kx. \end{align}

When the spring is compressed, $x < 0$. So \begin{align} m\ddot{y} = k|x|. \end{align} the LHS is exactly the same as before, and the RHS has now a positive sign because the force points to the right. But $x < 0$ means that $|x| = -x$, so we get \begin{align} m\ddot{x} = -kx, \end{align} exactly the same as before.

So there is no trouble.

Now you might protest and say, hey I want to define $x$ to be the distance of the free end from the equilibrium length, so $x \geq 0$, instead of as the displacement. Then what changes is this:

the coordinate is now a piecewise function. If the spring is stretched, $y = l + x$; if it is compressed, $y = l-x$.

For the stretched case, writing Newton's law gives \begin{align} m \ddot{y} = m\ddot{x} = -kx. \end{align} For the compressed case, \begin{align} m \ddot{y} = -m \ddot{x} = kx \implies m\ddot{x} = -kx. \end{align} Once again, we get back the same equations, and there is no problem.

-
+1, Ok that helps. I seem to have overlooked the part about $|X|=-x$ when $x<0$. This is where the negative sign was missing. Could you please check my DAlembert's principle derivation in my answer? Does it look correct? –  Asdfsdjlka Asdfsdjlka Feb 5 '13 at 8:04
@ Asdfsdjlka : note that if you read the other answers carefully, they say the same thing as I did. For your D'Alembert's principle, it is not right. The reason is because you do not know apriori what direction the acceleration is going to be in. So you cannot put in a minus sign like you did. First of all define right to be positive. For both cases, the force is $-kx$ (cf. Lubos' answer about the two signs cancelling). See that it encompasses the direction automatically. When $x > 0$ it is negative, hence to the left. When $x < 0$ it is positive and to the right. so it's just $-kx - mx''=0$. –  nervxxx Feb 5 '13 at 8:34
Sorry, I downvoted that because you have spoiled the nice analytic equations - linear in $x$ etc. - by tons of totally unnatural absolute values etc. There aren't any absolute values in the natural equations. At most, we could say that the opposite is true; some unnatural quantities for which the signs are vaguely defined or by convention positive are absolute values of the actual coordinates. But the right equations of motion just don't have any reason to be written with absolute values and/or to be split to cases for positive and negative $x$. –  Luboš Motl Feb 5 '13 at 9:58
Even if you make the discussion "complete" so that you discuss the cases of positive and negative $x$ separately, it's a totally unpedagogic treatment because the other side may get used to the notion that one should always split calculations to the cases of positive and negative values of variables. This would be a 100% waste of time in some minimal situation - with 10 variables, one would waste 1,024 times of the time and still failed to see that all this exercise with unnatural absolute values is a stupid self-inflicted wound. –  Luboš Motl Feb 5 '13 at 10:00
I think nervxxx explanation of the sign is brilliant. No book or web site explained it this way. The sign now comes out naturally the right way. Now I see why the sign on $x$ should be negative even though it is an extension at the same time for purpose of using Hooke;s law. Everyone else wanted to force the negative sign just because this is how it is supposed to be but with no clear explanation as to why. Like all the books do, they just say it is a restoring force and hence use negative sign in free body diagrams. I do not like rules. I like to derive things myself from first principles. –  Asdfsdjlka Asdfsdjlka Feb 5 '13 at 13:09

The situations are completely symmetric. When the spring is stretched, the "excess position" $x$ is positive and the force $-kx$ is negative, trying to return the spring to the equilibrium length (force pushes it to the left). When the spring is compressed, the "excess position" $x$ is negative and the force $-kx$ is positive (two signs, one from the explicit $-$ and one from $x\lt 0$, cancel), trying to return the spring to the equilibrium again (force is pushing to the right now).

Regardless of the origin and magnitude of the forces, it's always true that $F=ma=m\ddot x$.

-
sorry, do not get it. You say  the "excess position" x is negative ` but for Hooke's law, it is the extension amount that matter. extension amount is always a positive number. It is the force direction that matters for the signs. So I really do not see how you threw in the $-kx$ there. –  Asdfsdjlka Asdfsdjlka Feb 5 '13 at 6:13
Dont take the absolute value of the excess position. The minus sign in $-kx$ expresses the fact that the force acts in order to return the spring to equilibrium position. Visualize this with spring and mark an arrow for x axis. Try to get this important fact. –  Stefan Bischof Feb 5 '13 at 6:35
@StefanBischof, thanks, but Again, I want to derive this from free body diagram, using just force directions and Hooks law. You are just doing the same as what all books do, to tell student to just use $-kx$ becuase it is a restoring force. I want to derive this from first principles using free body diagram and Newton laws. –  Asdfsdjlka Asdfsdjlka Feb 5 '13 at 6:39
Dear asafsgesgshiehfafjkslhka, I have derived it from the first principles. Whatever other words you may add, $x$ for the compressed spring is clearly negative, that's how the coordinate is defined. It's just a damn coordinate that is positive on the right side and negative on the left side. So if you use the letter $x$ for any other law where it is positive in a similar situation, you must just realize that $x_{spring}=-x_{elsewhere}$. I tell you what the right sign of $x$ is, the answer is totally natural, and the only reason why you don't want to listen is that a wrong sign is your dogma. –  Luboš Motl Feb 5 '13 at 9:53

I don't see the problem. The $x$ refers to a coordinate here. When you have compressed the spring, your $x$ is negative, so your $-kx$ is positive as it should be. If you want your $x$ to instead refer to the positive magnitude of extension then you can't get a nice equation like $F = -kx$, you will have to make a piece-wise function to describe the force in terms of this $x$.

And to be clear, Hooke's law is this: For a spring, the magnitude of the force is proportional to the displacement from the equilibrium position and it is always opposite in direction to the displacement.

You seem to have made an argument using this definition, but I don't really understand it. If you want your $x$ to instead refer to the 'extension amount' which is always positive, you'll have to make a piece-wise definition for the force as I already said.

-
That is the problem. The $x$ can refer to coordinates and at the same time refer to extension for Hooke's law, and at the same time using free body diagram we use the direction of the force to tell the sign. We have to decide to either use the force vector direction to represent the sign or use just algebra. I choose vector directions. In Hooke's law, a spring extension of one meter gives same force magnitude. Only difference is direction of force. I indicated the direction in the force in free body diagram. (we do not say negative meter or positive meter extension, we just way one meter) –  Asdfsdjlka Asdfsdjlka Feb 5 '13 at 6:44