From 2bb047740fcdd9c000ed1c768a99984b3a21303b Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Thu, 19 Oct 2017 14:29:02 +0200 Subject: [PATCH] updated Tutorial.ipynb --- notebooks/Tutorial.ipynb | 115 +++++++++++++++++++++------------------ 1 file changed, 63 insertions(+), 52 deletions(-) diff --git a/notebooks/Tutorial.ipynb b/notebooks/Tutorial.ipynb index 02b89d9..90c2e1a 100644 --- a/notebooks/Tutorial.ipynb +++ b/notebooks/Tutorial.ipynb @@ -16,48 +16,11 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "data": { - "text/plain": [ - "LobattoLegendre{Float64}: Nodal Lobatto Legendre basis of degree 5" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "GaussLegendre{Float64}: Nodal Gauss Legendre basis of degree 5" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "using Revise\n", "using PolynomialBases\n", @@ -100,22 +63,11 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "data": { - "text/html": [ - "" - ] - }, - "execution_count": 43, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "using Revise\n", "using PolynomialBases\n", @@ -133,6 +85,65 @@ "scatter(ps, compute_error.(ps, LobattoLegendre), label=\"Lobatto\", xguide=L\"p\", yguide=\"Error\", yaxis=:log10)\n", "scatter!(ps, compute_error.(ps, GaussLegendre), label=\"Gauss\")" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Evaluation of Legendre Polynomials\n", + "\n", + "Legendre poylnomials $P_p$ are evaluated as `legendre(x, p)` using the three term recursion formula." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "using Revise\n", + "using PolynomialBases\n", + "using LaTeXStrings, Plots; pyplot()\n", + "\n", + "x = linspace(-1, 1, 10^3)\n", + "fig = plot(xguide=L\"x\")\n", + "for p in 0:5\n", + " plot!(fig, x, legendre.(x, p), label=\"\\$ P_$p \\$\")\n", + "end\n", + "fig" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Modal Matrices\n", + "\n", + "The Vandermonde matrix $V$ can be used to transform coeficients in a modal basis of Legendre polynomials to a nodal basis." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "using Revise\n", + "using PolynomialBases\n", + "\n", + "p = 7\n", + "basis = GaussLegendre(p)\n", + "V = legendre_vandermonde(basis)\n", + "\n", + "# the modal derivative matrix\n", + "Dhat = legendre_D(p)\n", + "# they should be equal\n", + "norm( basis.D - V * Dhat / V)" + ] } ], "metadata": {