<jupyter_start><jupyter_text>$$\frac{\partial^2 u}{\partial x^2} - \frac{\partial^2 u}{\partial y^2} = f(x,y)$$$N_x, N_y \in \mathbb{N}$, são os números de pontos interiores do grid, para completar há ainda os pontos $x_0, y_0$ e $x_f, y_f$ ou seja se $N_x = N_y = 3$ então nosso grid é um quadrado $5 \times 5$Nas condições de contorno temos:\\$$\begin{cases}(x,0) &= a\\(0,y) &= b\\(x, 1) &= c\\(1, y) &= d\end{cases}$$Uma discretização é:$$- \frac{U_{i+1,j} - 2U_{i,j} + U_{i-1,j}}{h^2_x} - \frac{U_{i,j+1} - 2U_{i,j} + U_{i,j-1}}{h^2_y} = f(x_i, y_j)$$Exemplo: $i=2, j=1$$$-U_{3,1} + 2U_{2,1} - U_{1,1} - U_{2,2} + 2U_{2,1} - \underbrace{U_{2,0}}_{a} = h^2 f(x_2, y_1)\\-U_{3,1} + 4U_{2,1} - U_{1,1} - U_{2,2} = h^2 f(x_2, y_1) + a$$Algumas definições$$U_{i,j} = U_n\\n = (i-1)+ N_x(j-1)\\j = int \left(\frac{n}{N_x} +1 \right)\\i = n-N_x(j-1)+1$$Seja C o conjunto dos pontos de contorno, então$$i = 1 \implies U_{n-1} \in C, b += U_{n-1}\\i = N_x \implies U_{n+1} \in C, b += U_{n+1}\\j=1 \implies U_{n-N_x} \in C, b += U_{n-N_x}\\j = N_y \implies U_{n+N_x} \in C, b += U_{n+N_x}\\$$<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
def f(x,y):
    return 1

def k(x,y):
    return 410

def solver_el(f, N, cont):
    A = []
    b = np.zeros(N**2)
    for n in range(N**2):
        
        j = n//N +1
        i = n-N*(j-1)+1
        a = np.zeros(N**2)
        h = 1/(N+1)
        xs = np.arange(0,1, h)[1:]
        ys = np.arange(0,1, h)[1:]    
        a[n] = 4
        b[n] = h**2*f(0,0)
        
        if i == 1:
            b[n] += cont[1]
        else:
            a[n-1] = -1
        
        if i == N:
            b[n] += cont[3]
        else:
            a[n+1] = -1
        
        if j == 1:
            b[n] += cont[2]
        else:
            a[n-N] = -1
        
        if j == N:
            b[n] += cont[0]
        else:
            a[n+N] = -1
        A.append(a)
    ys = np.linalg.solve(A,b)
    M = []
    for i in range(0,N**2,N):
        m = ys[i:i+N]
        M.append(m)
    return ys, M
cont = [0,0,0,0]
ys,M = solver_el(f, 30, cont)
plt.contourf(M, cmap = 'copper')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2340129749768304, 'fraction_numerical': 0.04865616311399444, 'mean_word_length': 1.9986111111111111, 'pattern_counts': {'":': 0, '<': 5, '<?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': '342036', 'license': 'MIT', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1055, 'n_words': 226, 'path': 'comp-cientifica-II-2019-2/Aulas/.ipynb_checkpoints/eh-de-pe-checkpoint.ipynb', 'repo_name': 'mirandagil/university-courses', 'size': '2158'}