Skip to content
Snippets Groups Projects
Commit f4c7fd74 authored by Frederic Weidling's avatar Frederic Weidling
Browse files

...

parent a3da5de5
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Wirkung der 1d-Poissongleichung auf einen Vektor
Es soll eine Funktion erstellt werden, die die Wirkung der 1d-Poissongleichung auf einen Vektor x simuliert. Die Idee dafür ist es am Anfang und Ende von x eine zusätzliche 0 einzufügen (sogenanntes zero padding) und dann entsprechende Ausschnitte auf x zu addieren.
%% Cell type:code id: tags:
``` python
from numpy import pad, array
a=array([1,2,3])
print(pad(a,1,mode='constant'))
```
%% Output
[0 1 2 3 0]
%% Cell type:markdown id: tags:
Nun die Funktion, die die Wirkung der 1d-Poissonmatrix auf einen Vektor berechnet:
%% Cell type:code id: tags:
``` python
def poisson1d(x):
h=pad(x,1,mode='constant')
y=2*x-h[:-2]-h[2:]
n=max(x.shape)+1
return y*n
```
%% Cell type:markdown id: tags:
Wir testen an zwei einfachen Beispielen, um uns von der Richtigkeit zu überzeugen:
%% Cell type:code id: tags:
``` python
from numpy import ones
print(poisson1d(a))
b=ones(9)
print(poisson1d(b))
```
%% Output
[ 0 0 16]
[ 10. 0. 0. 0. 0. 0. 0. 0. 10.]
%% Cell type:markdown id: tags:
Als Hinweise für den 2d-Fall:
%% Cell type:code id: tags:
``` python
c=array([[1,2],[3,4]])
pad(c,1, mode='constant')
```
%% Output
array([[0, 0, 0, 0],
[0, 1, 2, 0],
[0, 3, 4, 0],
[0, 0, 0, 0]])
%% Cell type:code id: tags:
``` python
d=array([1,2,3,4])
n=max(d.shape)
e=d.reshape((int(n**(1/2)),int(n**(1/2))))
print(e)
print(e.ravel())
```
%% Output
[[1 2]
[3 4]]
[1 2 3 4]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment