Skip to content
Snippets Groups Projects
Commit 13f39215 authored by penrose's avatar penrose
Browse files

matrix A assembled

parent 32deb0b8
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import numpy as np import numpy as np
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
First, the components of the following equation will be assembled: First, the components of the following equation will be assembled:
$$A \underline{u} = \underline{f} + B\underline{g}$$ $$A \underline{u} = \underline{f} + B\underline{g}$$
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
def u(x,y): def u(x,y):
return pow(x,4)*pow(y,5)-17*np.sin(x*y) return pow(x,4)*pow(y,5)-17*np.sin(x*y)
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
def f(x,y): def f(x,y):
return -(12*pow(x,2)*pow(y,5)+20*pow(x,4)*pow(y,3)+(pow(x,2)+pow(y,2))*17*np.sin(x*y)) return -(12*pow(x,2)*pow(y,5)+20*pow(x,4)*pow(y,3)+(pow(x,2)+pow(y,2))*17*np.sin(x*y))
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
n = 2 n = 3
h = pow(2,-n) h = pow(2,-n)
N = pow(2,n) N = pow(2,n)
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
def matrix_A(h): def matrix_A(h):
N = int(1/h) N = int(1/h)
m = pow(N-1,2) m = pow(N-1,2)
A = np.zeros((m,m)) A = pow(h,-2)*(np.zeros((m,m))-4*np.eye(m)+np.eye(m,k=1)+np.eye(m,k=-1)+np.eye(m,k=N-1)+np.eye(m,k=-(N-1)))
return A return A
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
matrix_A(h) matrix_A(h).shape
``` ```
%% Output %% Output
array([[0., 0., 0., 0., 0., 0., 0., 0., 0.], (49, 49)
[0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0.]])
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
def matrix_B(h): def matrix_B(h):
N = int(1/h) N = int(1/h)
m = pow(N-1,2) m = pow(N-1,2)
l = 4*N l = 4*N
B = np.zeros((m,l)) B = np.zeros((m,l))
return B return B
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
def vector_g(h): def vector_g(h):
N = int(1/h) N = int(1/h)
l = 4*N l = 4*N
g = np.zeros(l) g = np.zeros(l)
g[-1] = u(1,1) g[-1] = u(1,1)
return g return g
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
np.eye?
```
%% Output
%% Cell type:code id: tags:
``` python
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment