The equation for a steady state, one dimensional heat transfer problem is

Applying the finite difference method for this equation we get

This equation can be rewritten as

Imagine that we want to find the steady state temperature distribution in a large wall with 1 meter of thickness, submited to a prescribed temperature of 100C on its left face and 0C on its right face.

Consider the following grid for this problem.

Therefore, for the point P1 we have this equation

For the remaining points

Putting all in a matrix form, and letting $latex T_{0}=100C$ and $latex T_{5}=0C$

Here is the python code to solve this problem

import numpy as np from scipy.linalg import solve_banded def SolveBanded(A, D): # Find the diagonals ud = np.insert(np.diag(A,1), 0, 0) # upper diagonal d = np.diag(A) # main diagonal ld = np.insert(np.diag(A,-1), len(d)-1, 0) # lower diagonal # simplified matrix ab = np.matrix([ ud, d, ld, ]) return solve_banded((1, 1), ab, D ) if __name__ == "__main__": A = np.array([ [-2, 1, 0, 0], [ 1, -2, 1, 0], [ 0, 1, -2, 1], [ 0, 0, 1, -2] ]) D = np.array([-100, 0, 0, 0]) print "SciPy - 1D Conduction" print "A:", A print "D:", D print "Result:", SolveBanded(A, D)

The output for this code is

SciPy - 1D Conduction A: [[-2 1 0 0] [ 1 -2 1 0] [ 0 1 -2 1] [ 0 0 1 -2]] D: [-100 0 0 0] Result: [ 80. 60. 40. 20.]

That is $latex T_{1}=80C$, $latex T_{2}=60C$, $latex T_{3}=40C$ and $latex T_{2}=20C$.

This result agrees with the analytical solution for this problem

applied for the positions $latex P_{1}=0.2m$, $latex P_{2}=0.4m$ and so on.