{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Notebook for Exercise sheet 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Important: run the code cell below once when you just opened this notebook! It will make sure that plotting is enabled." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# some setup\n", "%matplotlib inline\n", "import numpy as np # makes numpy routines and data types available as np.[name ouf routine or data type]\n", "import matplotlib.pyplot as plt # makes plotting command available as plot.[name of command]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## H 2 (Dirichlet and Fejér kernel)\n", "\n", "Plot the Dirichlet and Fejér kernel for various values of n. Also generate a plot where you plot both kernels in one diagram." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Code for Dirichlet plots" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#code for Fejer plots" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## H3 (Interpolation with kernels)\n", "\n", "This exercise is about interpolation with the Gauss kernel $k(x,y)=\\exp(-\\gamma\\|x-y\\|_2^2)$.\n", "\n", "a) You are given a set of sampling points $X = \\{x_1,\\dots,x_n\\}$ with $x_i \\in \\mathbb R^2$ and function values at these points $f|_X = \\{f(x_1),\\dots,f(x_n)\\}$. Write some code which solves\n", "$$\n", " A_{X,X}\\alpha = f|_X,\n", "$$\n", "where $A_{X,X} = (k(x_i,x_j))_{i,j=1,\\dots,n}$ is the kernel matrix. You can use any of the linear algebra routines that come along with numpy. Also write a subroutine which evaluates the interpolant $s_{X,f|_X} = \\sum_{j=1}^n \\alpha_j k(x_j,\\cdot)$ at a given set of points $\\{y_1,\\dots,y_m\\}$." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# your code goes here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "b) For each of the following type of sampling points, write a subroutine which generates, for given $m \\in \\mathbb N$, $m^2$ sampling points:\n", "* uniform grid points in $[0,1]^2$\n", "* tensor-product Chebyshev points on $[0,1]^2$ given by\n", "$$\n", " (x_i,x_j) = \\left( \\cos\\left(\\frac{2i-1}{2m} \\pi\\right), \\cos\\left(\\frac{2j-1}{2m} \\pi\\right) \\right), \\quad i,j=1,\\dots,m\n", "$$\n", "* Halton points\n", "\n", "For the Halton sequence you can use the ghalton package. It is not in the conda package index, but in the pip package index." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Uniform grid points" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# tensor-product Chebyshev points" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Halton points" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "c) Use your code to interpolate the function\n", "$$\n", "f(x,y) = \n", "3(1-x)^2 \\exp(-x^2 - (y+1)^2)\\\\\n", " - 10(x/5 - x^3 - y^5) \\exp(-x^2-y^2)\\\\ \n", " - \\exp(-(x+1)^2 - y^2)/3\n", "$$\n", "on $[0,1]$ at $m^2$ uniform grid points, tensor-product Chebyshev points and Halton points for $m=10,20,30,40$ and Gauss parameter $\\gamma = 1,2$. Generate plots which show the pointwise error\n", "$$\n", " |f(y) - s_{X,f|_X}(y)| \n", "$$\n", "for each of type of sampling points. To this end, evaluate $f$ and $s_{X,f|_X}$ on a uniform grid with mesh size $1/1000$." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# your code goes here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "d) For each the sampling points used in c) plot the power function\n", "$$\n", " P_X^2(x) = k(x,x) - k(x,\\cdot)(x)\n", "$$\n", "Again, use a uniform grid with mesh size $1/1000$ to generate the plots. Compare the plots with the plots obtained in c)." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# your code goes here" ] } ], "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.1" } }, "nbformat": 4, "nbformat_minor": 0 }