Skip to content
Snippets Groups Projects
Commit 32deb0b8 authored by penrose's avatar penrose
Browse files

init of matrices and vectors

parent 3f05036c
No related branches found
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
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))
return A
```
%% Cell type:code id: tags:
``` python
matrix_A(h)
```
%% 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.]])
%% 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
```
%% 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
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))
return A
```
%% Cell type:code id: tags:
``` python
matrix_A(h)
```
%% 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.]])
%% 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
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment