Physics 374
Fall 2004
Prof. E. F. Redish

HW3, Problem 2
a.  The spring force is given by (Subscript[F, s])=-kx.  Let's first make sure this makes sense with the coordinate system given in the problem.  If the cart is right of the equilibrium point (x > 0) then the spring is stretched, so it should be trying to pull the cart left.  Indeed, we get (Subscript[F, s])<0 if we put in a positive x.  If the cart is left of the equilibrium position, the spring is compressed and should be trying to push the cart right.  Indeed, putting in a negative position value gives a positive (i.e. rightward) spring force.
	From N2: 
	                       ∑F = (Subscript[F, s])= ma
	                       so -kx = m (dv/dt)
	                    
	 So this equation, coupled with the definition of velocity, gives the set of differential equations we're after:
	  				(dv/dt) = ((-k)/m)x = -(ω^2)x
	  				(dx/dt) = v
	  				
b.  This set of equations can be solved exactly.  Substituting the second into the first gives
					(((d^2) x)/(dt^2)) = -(ω^2)x
Since this is a second order equation, it must have two independent solutions.  The general solution will be some linear combination of these two solutions.  By inspection, a sine and a cosine function are the two independent solutions.  Thus:
					x(t) = Acos(ωt) + Bsin(ωt)
And the general solution for v(t) follows from the second equation in our coupled set:
					v(t) = -Aωsin(ωt) + Bωcos(ωt)
And then the given initial conditions specify the specific solutions to our specific problem from the family of funcitons we've found.
			x(0) = (Subscript[x, o]) implies A = (Subscript[x, o]) and v(0) = (Subscript[v, o])implies B = (Subscript[v, o])/ω
All together:
					x(t) =  (Subscript[x, o])cos(ωt) +((Subscript[v, o])/ω)sin(ωt)
					v(t) = -(Subscript[x, o])ωcos(ωt) +  (Subscript[v, o])sin(ωt)

c.  Recall that Euler's Method is basically a stepping rule for numerically generating the solutions x(t) and v(t) one little step at a time.  When you're solving a system of two (or more) coupled equations like we are here, though, the order in which you take the little steps can make a difference.  We'll look at three different possibilities:
1) LAG X AND LAG V
	(Subscript[x, 2]) = (Subscript[x, 1])+ (dx/dt)Δt = (Subscript[x, 1])+ (Subscript[v, 1])Δt
and	(Subscript[v, 2])= (Subscript[v, 1])+ (dv/dt)Δt = (Subscript[v, 1])- ((Subscript[kx, 1])/m)Δt	...and so on where the next step is found by adding 1 
					to all the subscripts.
2) UPDATE X FIRST
	Similar to the last, only we first compute the new (i.e. (Subscript[x, 2])) position and then use this new position, instead of the old one, in computing the corresponding new velocity:
	(Subscript[x, 2]) = (Subscript[x, 1])+ (Subscript[v, 1])Δt
and	(Subscript[v, 2])= (Subscript[v, 1])- ((Subscript[kx, 2])/m)Δt
3) UPDATE V FIRST
	Similar to #2, only the other way around.
	(Subscript[v, 2])= (Subscript[v, 1])- ((Subscript[kx, 1])/m)Δt
and	(Subscript[x, 2]) = (Subscript[x, 1])+ (Subscript[v, 2])Δt

	See the Excel file accompanying this solution for the results of these three methods.

c.  The half step method is a hybrid of the "update x first" and 'update v first" methods.  In an attempt to cut down the error in the solution, the new x and v values are each computed using a half-stepped v or x, instead of stepping one all the way and the other not at all.
	Half Step Values:
		(Subscript[x, 3/2]) = (Subscript[x, 1]) + (Subscript[v, 1])(Δ(t/2))    and 	(Subscript[v, 3/2]) = (Subscript[v, 1]) - ((Subscript[kx, 1])/m)(Δ(t/2))
	Which Give:
		(Subscript[x, 2]) = (Subscript[x, 1])+ (Subscript[v, 3/2])Δt         and	(Subscript[v, 2])= (Subscript[v, 1])- ((Subscript[kx, 3/2])/m)Δt
	See the Excel file for the application of this method.

d.  We need some way to compare the four different sets of numerically generated solutions with the exact analytic solution to decide which of the numeric methods tends to give the most accurate results.  In the future we can use the methods that tend to be the most accurate when we don't have the benefit of an exact analytic solution.  A good comparison can be made via the total energy values, since they contain information on both x and v.  Using the analytic solutions:
	Total Energy = (1/2)k(x^2)+ (1/2)m(v^2)
	                      = (k/2)[((Subscript[x, o])^2)(cos^2)(ωt) + 2(Subscript[x, o])(Subscript[v, o])/ω cos(ωt)sin(ωt) + (((((Subscript[v, o])/ω)))^2)(sin^2)(ωt)]
	                       + (m/2)[((Subscript[x, o])^2)(ω^2)(sin^2)(ωt) - 2(Subscript[x, o])(Subscript[v, o])ω cos(ωt)sin(ωt) + ((Subscript[v, o])^2)(cos^2)(ωt)]
	                      = (k((Subscript[x, o])^2)/2)[(cos^2)(ωt)+(sin^2)(ωt)] + (m((Subscript[v, o])^2)/2)[(cos^2)(ωt)+(sin^2)(ωt)]
	                      = (k((Subscript[x, o])^2)/2) +  (m((Subscript[v, o])^2)/2)
So the total energy should be independent of time (of course) and should be 1.5J for the given problem's initial conditions.  
	It is then seen from the spreadsheets that the "lag x and lag y" method is clearly the worst.  The total energy of the system apparantly grows without bound.  The "update x first" and "update v first" methods both give about equally satisfactory results as both appear to keep the total energy bounded between 1.4J and 1.6J.  The half-step method is far superior in this particular application, though.  It keeps the total energy very nearly steady at 1.5J.  One has to look all the way to the fifth significant figure to see evidence of a slightly growing error as time progresses.

(Solution by T .  Bing)