I'm a total beginner to numerical methods. I just learned about applying Euler's method for first order equations. But now I have the following 2nd order system. The problem stems from 2 masses, which are connected to each other by three springs, and two of the springs are attached to walls. So $y_1$ would be the position of the first object and so on. $$y_1''=y_1-(y_1+y_2),$$ $$y_2''=y_2-3(y_1+y_2).$$

with initial conditions $$y_1(0) = a_1, \enspace y_2(0)=a_2,\enspace y_1'(0)=0,\enspace y_2'(0)=0.$$

Where $a_1,a_2$ are real numbers. This system can be solved analytically. Let $z=y_1+y_2$. The two equations can now be added, and we get $$z'' = z-4z = -3z,$$

which is a homogenic equation for $z$ and the solution is $$z=c_1 \cos\sqrt{3t}+c_2\sin\sqrt{3t},$$

where $c_1,c_2$ are constants. I then have these two second order equations $$y_1''=y_1 - c_1 \cos\sqrt{3t}-c_2\sin\sqrt{3t},$$ $$y_2''=y_2 -3c_1 \cos\sqrt{3t}-3c_2\sin\sqrt{3t}.$$

I could continue to solve for $y_1$ and $y_2$, but I'm asked to find a numerical solution. So at this point I have two problems. Whether or not I have developed this problem enough to apply some numerical method, and then what numerical methods should I look into. I'd appreciate any input.

  • $\begingroup$ See math.stackexchange.com/questions/2990229/…, stackoverflow.com/questions/55687304/… for previous attempts at similar problems. $\endgroup$ Mar 31, 2021 at 13:24
  • $\begingroup$ @Moo Whats wrong with the ICs? They indicate that the initial displacements of the two objects are $a_1$ and $a_2$ respectively. The derivatives indicate we start from rest. As for your second point, yes it is. The masses and spring constants are such that this occurs. Is it a problem? $\endgroup$
    – variations
    Mar 31, 2021 at 15:21
  • $\begingroup$ Well they are real numbers, I should have mentioned that. But for the displacements, I have not been given explicit numbers. $\endgroup$
    – variations
    Mar 31, 2021 at 15:26

1 Answer 1


Recast your system of 2nd order ODEs to a system of 4 first order ones, let's say $$y_1, \quad z_1=y_1', \quad y_2, \quad z_2=y_2'$$

By doing so, you can write $Y'=AY, Y(0)=Y_0$


$$ A= \begin{bmatrix}{} 0&1 &0 & 0\\ 0 &0& -1 & 0 \\ 0&0&0&1\\ -3 & 0 &2 & 0 \end{bmatrix}$$

and $$Y(0)=[y_1(0),y_1'(0),y_2(0),y_2'(0)]^T = [a_1,0,a_2,0]^T$$

The problem is linear and small. You can choose your favourite ODE solver. As you mentioned Forward Euler, here's the recurrence, given $Y_0$ and for $n\geq0$

$$Y_{n+1} = Y_n + kA Y_n = (1+kA)Y_n$$

Notice that the lack of A-stability requires a bit of care in choosing the step size $k$

A good compromise is given by its implicit counterpart, which is A-stable, and reads

$$Y_{n+1} = Y_n + kAY_{n+1} $$ which, solving for $Y_{n+1}$ reads $$Y_{n+1}=(I-kA)^{-1} Y_n$$ (DO NOT invert the matrix: solve the associated linear system instead)

If you're also familiar with matrix exponentials and their implementation (which is not straightforward at all), you can some appropriate routine and compute $Y_{n+1} =e^{kA}Y_n$ but this probably falls outside the scope of your problem.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.