1D boundary value problem - Your turn#
The same kind of matrix that is used in the demo is used to solve, for example, the 1D steady-state heat equation: \(\lambda^2 \dfrac{\partial^2 T}{\partial x^2} + q = 0\).
A rod of length \(L = 1\) m is maintained at \(T = 0\) °C at \(x = 0\) and is insulated at the other end (\(x = L\)). This rod is heated uniformly with a source \(q = 1\) K/s. The boundary conditions are \(T(0) = 0\) and \(\dfrac{\partial T}{\partial x}(L) = 0\). Assume \(\lambda = 1\).
Part (a)#
Discretize the heat equation using a central difference scheme. Use the off-centred difference scheme to enforce the zero-gradient boundary condition at \(x=L\). Set up the matrix equation of the form \(A\vec{T} = \vec{b}\).
TODO: Write your solution below#
Part (b)#
Solve this matrix equation using the np.linalg.inv()
command.
Use \(30\) points.
Plot the temperature \(T\) as a function of \(x\).
Add labels and a title.
# TODO: Write your solution below
Part (c)#
Find the analytical solution and plot it on the same figure.
TODO: Write your solution below#
Exporting your work#
When you’re ready, the easiest way to export the notebook is to File > Print
it and save it as a PDF.
Remove any excessively long, unrelated outputs first by clicking the arrow → next to the output box and then Show/hide output
.
Obviously don’t obscure any necessary output or graphs!