Section4.2Second Order Differential Equations¶ permalink
Subsection4.2.1First Example
For this first example, we'll look at a harmonic oscillator problem with unit constants.
\begin{equation}\frac{d^2 y}{dx^2} + y(x) = 0\label{men-16}\tag{4.2.1}\end{equation}Initial conditions:
\begin{equation}y(0) = 0\label{men-17}\tag{4.2.2}\end{equation}\begin{equation}\frac{dy}{dx}(0) = 1\label{men-18}\tag{4.2.3}\end{equation}Subsubsection4.2.1.1The General Solution
As before, we define \(y(x)\) and our DE. Notice the \(2\) as the third argument to the diff() method. This tells the method to differentiate twice. We could have used diff(y,x,x) instead. Notice also we are using the alias diff for derivative.
Now obtain the general solution:
This is the general solution as can be seen by the \(K_1,K_2\) constants.
\begin{equation}K_{2} \cos\left(x\right) + K_{1} \sin\left(x\right)\label{men-19}\tag{4.2.4}\end{equation}
Subsubsection4.2.1.2Initial Conditions
From the Docstring for desolve we find that \(ics\) should be \([0,0,1]\) so let us try it.
\begin{equation}\sin\left(x\right)\label{men-20}\tag{4.2.5}\end{equation}
Here we have again stored the solution to a variable sol_initial_con and used show() to pretty=print the output.
Try using some other initial conditions, for example, \([0,1,1]\)
\begin{equation}\cos\left(x\right) + \sin\left(x\right)\label{men-21}\tag{4.2.6}\end{equation}
As you can see these two particular solutions are instances of the general solution given above.
Subsubsection4.2.1.3Symbolic Differential Equations
Let us now try and solve the same equation this time with a mass \(m\) and spring constant \(k\).
\begin{equation}m\frac{d^2 y}{dx^2} + ky(x) = 0\label{men-22}\tag{4.2.7}\end{equation}Now we have to define additional variables for the two constants. It is also useful to add some constraints onto these variables. We do this using the assume() method:
\begin{equation}K_{2} \cos\left(\frac{\sqrt{k} x}{\sqrt{m}}\right) + K_{1} \sin\left(\frac{\sqrt{k} x}{\sqrt{m}}\right) \label{men-23}\tag{4.2.8}\end{equation}
Notice that we had to specify which of the variables \((x,m,k)\) is the independent variable using the ivar=x argument.