<jupyter_start><jupyter_text>Compute CFD solution$ h = \frac{1}{5}$ and $\epsilon = 10^{-10}$, below is Lh$$ A =  \begin{bmatrix} 1  &  0  &  0  &  0  &  0  & 0  \\ -r &  s  & -r  &  0  &  0  & 0  \\ 0  & -r  & s   &  -r &  0  & 0  \\ 0  &  0  & -r  &  s  & -r  & 0   \\ 0  &  0  & 0   & -r  &  s  & -r  \\ 0  &  0  & 0   &  0  &  0  &  1 \end{bmatrix}$$<jupyter_code>import numpy as np
from scipy.linalg import solve
e = 10**(-10)
interval_num = 5
r = e*(interval_num**2)
s = 2*r + 1
Rhf = np.zeros((interval_num+1))
Rhf[0] = 0
Rhf[-1] = 0
for i in range(interval_num):
  Rhf[i+1] = Rhf[i] + 1/interval_num
Lhuh=np.zeros((interval_num+1,interval_num+1))
Lhuh[0,0]=1
Lhuh[-1,-1]=1
for i in range(interval_num-1):
  Lhuh[i+1,i]=-r
  Lhuh[i+1,i+1]=s
  Lhuh[i+1,i+2]=-r
uh = solve(Lhuh,Rhf)
uh<jupyter_output><empty_output><jupyter_text>Compare CFD with FEM<jupyter_code>e = 10**(-10)
interval_num = 9
r = e*(interval_num**2)
s = 2*r + 1
Rhf = np.zeros((interval_num+1))
Rhf[0] = 0
Rhf[-1] = 0
for i in range(interval_num):
  Rhf[i+1] = Rhf[i] + 1/interval_num
Lhuh=np.zeros((interval_num+1,interval_num+1))
Lhuh[0,0]=1
Lhuh[-1,-1]=1
for i in range(interval_num-1):
  Lhuh[i+1,i]=-r
  Lhuh[i+1,i+1]=s
  Lhuh[i+1,i+2]=-r
uh = solve(Lhuh,Rhf)
uh
diff_arr = np.zeros(10)
interval_num = 9
e = 10**(-10)
Rhf = np.zeros((interval_num+1))
Rhf[0] = 0
for i in range(interval_num):
  Rhf[i+1] = Rhf[i] + 1/(interval_num-1)
  x = Rhf[i]
  u = x - (np.exp((x - 1)/np.sqrt(e)) - np.exp(- (x+1)/np.sqrt(e))) / (1 - np.exp(- 2 / np.sqrt(e)))
  diff = np.abs(u - uh[i])
  diff_arr[i] = diff  
diff_arr<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.22008679479231247, 'fraction_numerical': 0.06509609423434594, 'mean_word_length': 3.11734693877551, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '197337', 'license': 'MIT', 'n_tokens_mistral': 887, 'n_tokens_neox': 839, 'n_words': 164, 'path': 'hw/hw8code.ipynb', 'repo_name': 'Bertha-ding/20MA573-yuning-ding', 'size': '1613'}