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

matrix A assembled

parent 32deb0b8
Branches
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
%% Cell type:code id: tags:
``` python
import numpy as np
```
%% Cell type:markdown id: tags:
First, the components of the following equation will be assembled:
$$A \underline{u} = \underline{f} + B\underline{g}$$
%% Cell type:code id: tags:
``` python
def u(x,y):
return pow(x,4)*pow(y,5)-17*np.sin(x*y)
```
%% Cell type:code id: tags:
``` python
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))
```
%% Cell type:code id: tags:
``` python
n = 2
n = 3
h = pow(2,-n)
N = pow(2,n)
```
%% Cell type:code id: tags:
``` python
def matrix_A(h):
N = int(1/h)
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
```
%% Cell type:code id: tags:
``` python
matrix_A(h)
matrix_A(h).shape
```
%% Output
array([[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.],
[0., 0., 0., 0., 0., 0., 0., 0., 0.]])
(49, 49)
%% Cell type:code id: tags:
``` python
def matrix_B(h):
N = int(1/h)
m = pow(N-1,2)
l = 4*N
B = np.zeros((m,l))
return B
```
%% Cell type:code id: tags:
``` python
def vector_g(h):
N = int(1/h)
l = 4*N
g = np.zeros(l)
g[-1] = u(1,1)
return g
```
%% Cell type:code id: tags:
``` 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