{ "metadata": { "name": "", "signature": "sha256:54681fa9c17f69bb87bb5ec7650390f8cc9d223fe231f519b1e3ebf205d14e8f" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "import matplotlib.pyplot as plt\n", "from mpl_toolkits.mplot3d.axes3d import Axes3D\n", "import numpy as np" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 13 }, { "cell_type": "code", "collapsed": false, "input": [ "def hats2D(x,y,xlevel,ylevel):\n", " result = 0\n", " for i in range(2**(xlevel-1)):\n", " xStart = i*(1/2**(xlevel-1))\n", " xEnd = (i+1)*(1/2**(xlevel-1))\n", " for j in range(2**(ylevel-1)):\n", " yStart = j*(1/2**(ylevel-1))\n", " yEnd = (j+1)*(1/2**(ylevel-1))\n", " result += hat2D(x,y,xStart,xEnd,yStart,yEnd)\n", " return result\n", "def hat2D(x,y,xStart,xEnd,yStart,yEnd):\n", " midx = (xEnd + xStart)/2\n", " hx = (xEnd - xStart)/2\n", " midy = (yEnd + yStart)/2\n", " hy = (yEnd - yStart)/2\n", " fx = max((hx - abs(x-midx))/hx,0)\n", " fy = max((hy - abs(y-midy))/hy,0)\n", " result = fx * fy\n", " return result" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 14 }, { "cell_type": "code", "collapsed": false, "input": [ "xlevel = 1\n", "ylevel = 2\n", "fig = plt.figure(figsize=(14,6))\n", "x = np.linspace(0,1,100)\n", "y = np.linspace(0,1,100)\n", "X,Y = np.meshgrid(x, y)\n", "Z = [[hats2D(X[i][j],Y[i][j],xlevel,ylevel) for j in range(len(X[i]))] for i in range(len(X))]\n", "ax = fig.add_subplot(1, 1, 1, projection='3d')\n", "p = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=\"seismic\", linewidth=0, antialiased=False)\n", "p2 = ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)\n", "plt.show()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 16 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }