[Go to the Notes on Diffy Qs home page]

Notes on Diffy Qs - Sage demos for section 1.9

Press the Evaluate button below to launch the Sage demonstration. You may have to wait a little before the graph appears. Be patient. To change the function, you should edit the code and press the Evaluate button again.

Plotting Example 1.9.1: Transport equation

Let us work through the solution to \( u_x + u_t = 0,\) the transport equation, for \(-\infty < x < \infty , \) \(t \geq 0, \) with the initial condition \(u(x,0) = e^{-x^2} .\) That is, Example 1.9.2 in the book with \(\alpha=1\) and \(f(x) = e^{-x^2} .\)

The characteristic curves are the sets where \(\xi = \text{constant},\) so we need to write \(\xi\) as a function of \(x\) and \(t\) and plot the level sets of this function. We found the characteristic coordinates \((\xi,s)\) to be given by \(\xi=x-t,\) \(s=t .\) So we find the level sets of \(x-t .\) The \(x\) axis is the horizontal one and \(t\) the vertical one.

In the book, we solved the equation to find

\(\displaystyle u(x,t) = e^{-(x-t)^2} . \)

Before graphing \(u\) in three dimensions, we draw the values of \(u\) as colors and overlay the characteristics. Note how the function is constant (same color) along the characteristic since the ODE along the characteristics is \(\frac{du}{ds} = 0 . \)

Next, we plot the graph of \(u(x,t)\) in 3 dimensions. Note that Sage currently (unless this has been fixed already) labels the axes a little confusingly, so the \(t\) axis is labeled as \(y .\) You should be able to rotate the graph by clicking and dragging.

Plotting Example 1.9.3

Let us work through \( xu_x + u_t + 2u = 0,\) \(-\infty < x < \infty , \) \(t \geq 0, \) with the initial condition \(u(x,0) = \cos(x) .\)

First, we plot the characteristic curves \(\xi = \text{constant}.\) In this example, the characteristic coordinates \((\xi,s)\) were given by \(x=\xi e^s,\) \(t=s .\) Solving for \(\xi\) in terms of \(x\) and \(t\) we find \(\xi=xe^{-t}.\) We will only plot \(x\) in the range \(-5\) to \(5\) and the \(t\) in the range \(0\) to \(1.\) So to avoid a narrow graph we set the aspect ratio to 8 to stretch the \(t\) axis by 8 times.

In the book, we solved the equation to find

\(\displaystyle u(x,t) = e^{-2t} \cos(xe^{-t}) . \)

We again make a contour plot of \(u\) with the characteristics overlaid. In this case, the ODE along the characteristic is \(\frac{du}{ds}+2u=0 ,\) which has the general solution \(u = Ce^{-2s} .\) So the solution decays towards zero exponentially as we move along the characteristic.

And finally, the graph of \(u(x,t)\) in 3 dimensions. Here we also stretch the vertical axis 3 times.

Valid HTML 5 Valid CSS!