From f4c7fd7429f8033f8016070943bbac9949d4b71b Mon Sep 17 00:00:00 2001 From: Frederic Weidling <fweidli@client61.num.math.uni-goettingen.de> Date: Fri, 23 Dec 2016 09:04:19 +0100 Subject: [PATCH] ... --- 10_Poisson1d_function.ipynb | 168 ++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 10_Poisson1d_function.ipynb diff --git a/10_Poisson1d_function.ipynb b/10_Poisson1d_function.ipynb new file mode 100644 index 0000000..40593fa --- /dev/null +++ b/10_Poisson1d_function.ipynb @@ -0,0 +1,168 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Wirkung der 1d-Poissongleichung auf einen Vektor\n", + "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", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0 1 2 3 0]\n" + ] + } + ], + "source": [ + "from numpy import pad, array\n", + "\n", + "a=array([1,2,3])\n", + "print(pad(a,1,mode='constant'))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Nun die Funktion, die die Wirkung der 1d-Poissonmatrix auf einen Vektor berechnet:" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def poisson1d(x):\n", + " h=pad(x,1,mode='constant')\n", + " y=2*x-h[:-2]-h[2:]\n", + " n=max(x.shape)+1\n", + " return y*n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Wir testen an zwei einfachen Beispielen, um uns von der Richtigkeit zu überzeugen:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false, + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[ 0 0 16]\n", + "[ 10. 0. 0. 0. 0. 0. 0. 0. 10.]\n" + ] + } + ], + "source": [ + "from numpy import ones\n", + "\n", + "print(poisson1d(a))\n", + "\n", + "b=ones(9)\n", + "print(poisson1d(b))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Als Hinweise für den 2d-Fall: " + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[0, 0, 0, 0],\n", + " [0, 1, 2, 0],\n", + " [0, 3, 4, 0],\n", + " [0, 0, 0, 0]])" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c=array([[1,2],[3,4]])\n", + "pad(c,1, mode='constant')" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1 2]\n", + " [3 4]]\n", + "[1 2 3 4]\n" + ] + } + ], + "source": [ + "d=array([1,2,3,4])\n", + "n=max(d.shape)\n", + "e=d.reshape((int(n**(1/2)),int(n**(1/2))))\n", + "print(e)\n", + "print(e.ravel())" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.5.2" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} -- GitLab