From 4e9d6f32239a9593bfc73acc37aaf37c07c815d5 Mon Sep 17 00:00:00 2001 From: Benjamin Berkels <berkels@aices.rwth-aachen.de> Date: Wed, 28 Apr 2021 10:56:14 +0200 Subject: [PATCH] added IPython notebook for Remark 1.5.1 --- rem-151.ipynb | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 rem-151.ipynb diff --git a/rem-151.ipynb b/rem-151.ipynb new file mode 100644 index 0000000..3f16778 --- /dev/null +++ b/rem-151.ipynb @@ -0,0 +1,82 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### IPython notebook for Remark 1.5.1 from the lecture" + ] + }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "import numpy as np\n", + "from IPython.display import display, Math\n", + "from sympy import Float, latex\n", + "\n", + "\n", + "def k(s, t, d):\n", + " return d / np.power(d ** 2 + (s - t) ** 2, 3 / 2)\n", + "\n", + "\n", + "d = 0.1\n", + "n = 80\n", + "h = 1 / n\n", + "display(Math(rf\"n = {n},\\; d = {d},\\; h ={h}\"))\n", + "\n", + "s = (np.arange(n) + 0.5) * h\n", + "t = (np.arange(n) + 0.5) * h\n", + "display(Math(rf't_j=s_j=(j-\\tfrac12)h,\\; j=1,\\ldots,{n}'))\n", + "A = h * k(s[:, np.newaxis], t[np.newaxis, :], d)\n", + "display(Math(r'A_{i,j}:=h \\, k(s_i,t_j),\\; k(s,t) := \\frac{d}{(d^2 + (s-t)^2)^{3/2}}'))" + ], + "outputs": [], + "execution_count": null + }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "eigvals = np.linalg.eig(A)[0]\n", + "lambda_max = np.amax(eigvals)\n", + "lambda_min = np.amin(eigvals)\n", + "cond_A = lambda_max / lambda_min\n", + "display(Math(r\"\\lambda_\\text{max} = \" + latex(Float(lambda_max, 4), max=1)))\n", + "display(Math(r\"\\lambda_\\text{min} = \" + latex(Float(lambda_min, 4))))\n", + "display(Math(r\"\\operatorname{cond(A)} = \" + latex(Float(cond_A, 2))))" + ], + "outputs": [], + "execution_count": null + }, + { + "cell_type": "code", + "metadata": {}, + "source": [], + "outputs": [], + "execution_count": null + } + ], + "metadata": { + "anaconda-cloud": {}, + "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.6.1" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} \ No newline at end of file -- GitLab