# Boundary Value Problem Example - Heated Rod
## CH EN 2450 - Numerical Methods
**Prof. Tony Saad (<a>www.tsaad.net</a>) <br/>Department of Chemical Engineering <br/>University of Utah**
<hr/>


```python
%matplotlib inline
%config InlineBackend.figure_format = 'svg'
import matplotlib.pyplot as plt
import numpy as np
```

# Dirichlet Boundary Conditions

The coefficient matrix looks like
\begin{equation}
\left[ {\begin{array}{*{20}{c}}
1&0&0& \cdots &0\\
1& - \left( 2 + \Delta {x^2}H \right)&1&0& \vdots \\
0& \ddots & \ddots & \ddots &0\\
 \vdots &0&1& - \left( 2 + \Delta x^2H \right)&1\\
0& \cdots &0&0&1
\end{array}} \right]
\left( {\begin{array}{*{20}{c}}
T_1\\
\begin{array}{l}
T_2\\
T_3
\end{array}\\
\begin{array}{l}
 \vdots \\
 \vdots 
\end{array}\\
T_{n - 1}\\
T_n
\end{array}} \right) 
= \left( {\begin{array}{*{20}{c}}
T_\rm{left}\\
- T_\infty \Delta {x^2}H\\
 \vdots \\
- T_\infty\Delta {x^2}H\\
T_\rm{right}
\end{array}} \right)
\end{equation}


```python
n = 200 # number of desired grid points
L = 1.0 # rod length
Tleft = 300
Tright = 300
Tinf = 500
h = 1 # heat transfer coefficient, due to advection of surrounding air

x = np.linspace(?,?,?) # create an array for the grid points x_i
dx = x[1] - x[0] # calculate grid spacing (grid spacing is constant here)

# create lower diagonal vector
ld = ?
ld[?] = ? # fix the end point

# create main diagonal vector
d = ?
d[0] = 1.0 # fix the end point
d[-1] = 1.0 # fix the end point

# create upper diagonal vector
ud = ?
ud[?] = ? # fix the end point

# combine those into a matrix
A = np.diag(ld,?) + np.diag(d, ?) + np.diag(ud, ?)

# build the RHS array
rhs = ?
rhs[0] = ? # fix the left boundary
rhs[-1] = ? # fix the right boundary

# solve the system of equations
sol = np.linalg.solve(?, ?)

plt.plot(?, ?)
plt.grid()
```


    

    



```python
temperature = np.tile(sol,(40,1))
plt.imshow(temperature,cmap='jet')
```




    <matplotlib.image.AxesImage at 0x119ecc910>




    

    


976507b5ccceab0b9d9b9758309857aa5285beef
ipynb
Jupyter Notebook
topics/boundary value problems/Boundary Value Problem Example - Heated Rod - With Gaps.ipynb
jomorodi/NumericalMethods
e040693001941079b2e0acc12e0c3ee5c917671c
MIT
2019-03-27T05:22:34.000Z
2021-01-27T10:49:13.000Z
topics/boundary value problems/Boundary Value Problem Example - Heated Rod - With Gaps.ipynb
jomorodi/NumericalMethods
e040693001941079b2e0acc12e0c3ee5c917671c
MIT
topics/boundary value problems/Boundary Value Problem Example - Heated Rod - With Gaps.ipynb
jomorodi/NumericalMethods
e040693001941079b2e0acc12e0c3ee5c917671c
MIT
2019-12-29T23:31:56.000Z
2021-12-28T19:04:10.000Z
Qwen/Qwen-72B
1. YES
2. YES