<jupyter_start><jupyter_text>Hyperbollic Equations$$\frac{\partial U}{\partial t} + a \frac{\partial U}{\partial x} = 0$$<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
Nx = 10
Nt = 5
hx = 1/(Nx+1)
ht = 0.01
tf = 2
a = 1
sigma = a*ht/hx

## Boundary conditions
left_x = 0
right_x = 1


xs = np.arange(0,1+hx,hx)

ts = np.arange(0,tf+ht, ht)

Us = [[]]

## setting initial condition on t = 0
for x in xs:
    if (x < 0.5):
        newU = 0
    else:
        newU = 1
    Us[-1].append(newU)
        
        
## solving for t+1

for t in ts[:-1]:
    U = []
    for x in range(1,len(xs)-1):   
        newU = Us[-1][x] - sigma/2 * (Us[-1][x+1] - Us[-1][x-1])
        U.append(newU)
    U.append(1)
    U.insert(0,0)
    Us.append(U)
plt.figure(figsize=(12,10))
for i in range(len(Us)):
    plt.plot(xs,Us[i])
plt.grid(alpha = 0.5)
plt.show()
Nx = 20
Nt = 30
hx = 1/(Nx+1)
ht = 0.01
tf = 2
a = 1
sigma = a*ht/hx

## Boundary conditions
left_x = 0
right_x = 1


xs = np.arange(0,1+hx,hx)

ts = np.arange(0,tf+ht, ht)

Us = [[]]

## setting initial condition on t = 0
for x in xs:
    if (x < 0.5):
        newU = 0
    else:
        newU = 1
    Us[-1].append(newU)
        
        
## solving for t+1

for t in ts[:-1]:
    U = []
    for x in range(1,len(xs)-1):   
        newU = (1-sigma)*Us[-1][x] + sigma * Us[-1][x-1]
        U.append(newU)
    U.append(1)
    U.insert(0,0)
    Us.append(U)
plt.figure(figsize=(8,4))
for i in range(len(Us)):
    plt.plot(xs,Us[i])
plt.grid(alpha = 0.5)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19161290322580646, 'fraction_numerical': 0.05032258064516129, 'mean_word_length': 2.3141025641025643, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '327815', 'license': 'MIT', 'n_tokens_mistral': 761, 'n_tokens_neox': 710, 'n_words': 165, 'path': 'comp-cientifica-II-2019-2/Aulas/Hyperbolic equations.ipynb', 'repo_name': 'mirandagil/university-courses', 'size': '1550'}