From 13f392157cb28fc0cfd35533cbbc4c553d67be4e Mon Sep 17 00:00:00 2001 From: penrose <penrose@mi.fu-berlin.de> Date: Thu, 6 May 2021 21:57:10 +0200 Subject: [PATCH] matrix A assembled --- five_point_stencil.ipynb | 88 ++++++++++++++++++++++++++++++++-------- 1 file changed, 71 insertions(+), 17 deletions(-) diff --git a/five_point_stencil.ipynb b/five_point_stencil.ipynb index 2846fb8..06119d9 100644 --- a/five_point_stencil.ipynb +++ b/five_point_stencil.ipynb @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -45,54 +45,46 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ - "n = 2\n", + "n = 3\n", "h = pow(2,-n)\n", "N = pow(2,n)" ] }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "def matrix_A(h):\n", " N = int(1/h)\n", " m = pow(N-1,2)\n", - " A = np.zeros((m,m))\n", + " 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)))\n", " return A" ] }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([[0., 0., 0., 0., 0., 0., 0., 0., 0.],\n", - " [0., 0., 0., 0., 0., 0., 0., 0., 0.],\n", - " [0., 0., 0., 0., 0., 0., 0., 0., 0.],\n", - " [0., 0., 0., 0., 0., 0., 0., 0., 0.],\n", - " [0., 0., 0., 0., 0., 0., 0., 0., 0.],\n", - " [0., 0., 0., 0., 0., 0., 0., 0., 0.],\n", - " [0., 0., 0., 0., 0., 0., 0., 0., 0.],\n", - " [0., 0., 0., 0., 0., 0., 0., 0., 0.],\n", - " [0., 0., 0., 0., 0., 0., 0., 0., 0.]])" + "(49, 49)" ] }, - "execution_count": 30, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "matrix_A(h)" + "matrix_A(h).shape" ] }, { @@ -123,6 +115,68 @@ " return g " ] }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\u001b[0;31mSignature:\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0meye\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mM\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mk\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m<\u001b[0m\u001b[0;32mclass\u001b[0m \u001b[0;34m'float'\u001b[0m\u001b[0;34m>\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0morder\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'C'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mDocstring:\u001b[0m\n", + "Return a 2-D array with ones on the diagonal and zeros elsewhere.\n", + "\n", + "Parameters\n", + "----------\n", + "N : int\n", + " Number of rows in the output.\n", + "M : int, optional\n", + " Number of columns in the output. If None, defaults to `N`.\n", + "k : int, optional\n", + " Index of the diagonal: 0 (the default) refers to the main diagonal,\n", + " a positive value refers to an upper diagonal, and a negative value\n", + " to a lower diagonal.\n", + "dtype : data-type, optional\n", + " Data-type of the returned array.\n", + "order : {'C', 'F'}, optional\n", + " Whether the output should be stored in row-major (C-style) or\n", + " column-major (Fortran-style) order in memory.\n", + "\n", + " .. versionadded:: 1.14.0\n", + "\n", + "Returns\n", + "-------\n", + "I : ndarray of shape (N,M)\n", + " An array where all elements are equal to zero, except for the `k`-th\n", + " diagonal, whose values are equal to one.\n", + "\n", + "See Also\n", + "--------\n", + "identity : (almost) equivalent function\n", + "diag : diagonal 2-D array from a 1-D array specified by the user.\n", + "\n", + "Examples\n", + "--------\n", + ">>> np.eye(2, dtype=int)\n", + "array([[1, 0],\n", + " [0, 1]])\n", + ">>> np.eye(3, k=1)\n", + "array([[0., 1., 0.],\n", + " [0., 0., 1.],\n", + " [0., 0., 0.]])\n", + "\u001b[0;31mFile:\u001b[0m ~/miniconda3/envs/Manhatten/lib/python3.7/site-packages/numpy/lib/twodim_base.py\n", + "\u001b[0;31mType:\u001b[0m function\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "np.eye?" + ] + }, { "cell_type": "code", "execution_count": null, -- GitLab