Skip to main content
\(\newcommand{\Z}{\mathbb{Z}} \newcommand{\reals}{\mathbb{R}} \newcommand{\real}[1]{\mathbb{R}^{#1}} \newcommand{\fe}[2]{#1\mathopen{}\left(#2\right)\mathclose{}} \newcommand{\cinterval}[2]{\left[#1,#2\right]} \newcommand{\ointerval}[2]{\left(#1,#2\right)} \newcommand{\cointerval}[2]{\left[\left.#1,#2\right)\right.} \newcommand{\ocinterval}[2]{\left(\left.#1,#2\right]\right.} \newcommand{\point}[2]{\left(#1,#2\right)} \newcommand{\fd}[1]{#1'} \newcommand{\sd}[1]{#1''} \newcommand{\td}[1]{#1'''} \newcommand{\lz}[2]{\frac{d#1}{d#2}} \newcommand{\lzn}[3]{\frac{d^{#1}#2}{d#3^{#1}}} \newcommand{\lzo}[1]{\frac{d}{d#1}} \newcommand{\lzoo}[2]{{\frac{d}{d#1}}{\left(#2\right)}} \newcommand{\lzon}[2]{\frac{d^{#1}}{d#2^{#1}}} \newcommand{\lzoa}[3]{\left.{\frac{d#1}{d#2}}\right|_{#3}} \newcommand{\abs}[1]{\left|#1\right|} \newcommand{\sech}{\operatorname{sech}} \newcommand{\csch}{\operatorname{csch}} \newcommand \dd[1] { \,\textrm d{#1} } \newcommand \de[2] { \frac{\mathrm d{#1}}{\mathrm d{#2}} } \newcommand \intl[4]{ \int\limits_{#1}^{#2}{#3}\dd{#4} } \newcommand\at[2]{\left.#1\right|_{#2}} \newcommand{\lt}{ < } \newcommand{\gt}{ > } \newcommand{\amp}{ & } \)

Section4.2Second Order Differential Equations

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.