{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# PDE python exercise 2" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "In this exercise we will focus on work the manipulation of arrays and 3D plotting. We will use a simple mathematical expression as a background for the development of our python code." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "First we import our mandatory modules" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from mpl_toolkits.mplot3d import axes3d" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "In this exercise we will use a function $F$ which is dependent upon two variables $x$ and $y$. This equation reads:\n", "$$ F = x^2*y^2+\\sin(x)+\\cos(y)$$" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "In this problem, you need to:\n", "1. $x$ and $y$ must be defined using a `numpy meshgrid` in the range 0 to 1\n", "2. Define a function which computes $F$ with both $x$ and $y$ as input\n", "3. Define a function which computes the partial derivative of $F$ with respect to $x$\n", "4. Define a function which computes the partial derivative of $F$ with respect to $y$\n", "5. Plot the resulting function $F$ and its derivatives $\\frac{\\partial F}{\\partial x}$ and $\\frac{\\partial F}{\\partial y}$ using a 3D plot\n", "6. Plot the resulting function $F$ and its derivatives $\\frac{\\partial F}{\\partial x}$ and $\\frac{\\partial F}{\\partial y}$ using a 2D contour plot\n", "\n", "In this python exercise, $F$ and its derivatives have to be computed for a given range of $x$ and $y$.\n", "The function must be evaluated as:\n", "´F = func(X,Y)´\n", "\n", "Without using a `for` loop:\n", "\n", "7. Compute the partial derivates of $F$ with respect to both $x$ and $y$ (1st derivative) using a backward difference.\n", "8. Compute the partial derivates of $F$ with respect to both $x$ and $y$ (1st derivative) using a forward difference." ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.9.10 | packaged by conda-forge | (main, Feb 1 2022, 21:27:43) \n[Clang 11.1.0 ]" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "072f120aa02d08ea61d001fa93115a43c81ff98089754e42d3890c56566da5f7" } } }, "nbformat": 4, "nbformat_minor": 2 }