```python
import numpy as np

def f(x):   # Given Function for the top boundary
    return x**2 - x

def make_matrices(n):  ## Function to make the coefficient matrix and result matrix
    length = (n-2)**2
    result = np.zeros(shape=((length,1)))
    coef_matrix = np.zeros(shape=((length,length)))
    
    side = n-2
    
    for row in range(length):
        coef_matrix[row,row] = 1
        
        if row != 0 and row%side != 0:
            coef_matrix[row,row-1] = -1/4

        if row != length-1 and (row+1)%(side) != 0:
            coef_matrix[row,row+1] = -1/4
        
        if row - side >= 0:
            coef_matrix[row,row-side] = -1/4
        
        if row + side <= length-1:
            coef_matrix[row,row+side] = -1/4
    
    for index in range(1,side+1):
        x = index/(n-1)
        result[(length-1-side)+index,0] = round(0.25*f(x),3)
        
    return coef_matrix, result
```


```python
def calculate_variables(coef_matrix, result): ## Function to execute the linear algebra
    inv_coef = np.linalg.inv(coef_matrix)
    variables = np.matmul(inv_coef,result)
    return inv_coef, variables
```


```python
import sympy
sympy.init_printing(use_unicode=True)
```

### Example for a Matrix of size 4


```python
coef_matrix, result = make_matrices(4)
```


```python
print('Coefficient Matrix: ')
sympy.Matrix(coef_matrix.tolist())
```


```python
print('The Result Matrix on the right before taking the inverse of the coefficient matrix: ')
sympy.Matrix(result.tolist())
```


```python
inv_coef, output = calculate_variables(coef_matrix, result)
```


```python
print('The inverse of the Coefficient Matrix is:')
sympy.Matrix(inv_coef.tolist())
```


```python
print('The Final output matrix with the four variables is:')
sympy.Matrix(output.tolist())
```

### Example for Matrix of size 6


```python
coef_matrix, result = make_matrices(6)
```


```python
print('Coefficient Matrix: ')
sympy.Matrix(coef_matrix.tolist())
```


```python
print('The Result Matrix on the right before taking the inverse of the coefficient matrix: ')
sympy.Matrix(result.tolist())
```


```python
inv_coef, output = calculate_variables(coef_matrix, result)
```


```python
print('The Final output matrix with the 4*4 = 16 variables is:')
sympy.Matrix(output.tolist())
```


```python
len(output)
```

08a4417d7f09a8d4e1bb9070af0038a85b3c7806
ipynb
Jupyter Notebook
Solving LaPlace's Equations.ipynb
sohitmiglani/Practical-Simulations-and-Social-Networks
5b6741794004d8347ecfe90f21ea5828b174a71c
MIT
2019-01-16T13:36:05.000Z
2020-09-23T19:25:37.000Z
Solving LaPlace's Equations.ipynb
sohitmiglani/Practical-Simulations-and-Social-Networks
5b6741794004d8347ecfe90f21ea5828b174a71c
MIT
Solving LaPlace's Equations.ipynb
sohitmiglani/Practical-Simulations-and-Social-Networks
5b6741794004d8347ecfe90f21ea5828b174a71c
MIT
Qwen/Qwen-72B
1. YES
2. YES