summaryrefslogtreecommitdiff
path: root/tutorials/module_3/notebook_3
diff options
context:
space:
mode:
authorChristian Kolset <christian.kolset@gmail.com>2025-05-09 09:53:20 -0600
committerChristian Kolset <christian.kolset@gmail.com>2025-05-09 09:53:20 -0600
commit0d4e770dc06763d225dce66f82bd49b052bead06 (patch)
tree3b4e9fa683c89f8eafb8a7454fc191d9e8739a34 /tutorials/module_3/notebook_3
parent3eb4be2a880eed828c983c8a30d73faa8e6f4746 (diff)
Added auto-generated (md converted) notebooks to modules. Added module 3 tutorials
Diffstat (limited to 'tutorials/module_3/notebook_3')
-rw-r--r--tutorials/module_3/notebook_3/numerical_differentiation.ipynb140
-rw-r--r--tutorials/module_3/notebook_3/numerical_integration.ipynb27
-rw-r--r--tutorials/module_3/notebook_3/numerical_methods.ipynb52
-rw-r--r--tutorials/module_3/notebook_3/ode.ipynb23
-rw-r--r--tutorials/module_3/notebook_3/roots_optimization.ipynb25
5 files changed, 267 insertions, 0 deletions
diff --git a/tutorials/module_3/notebook_3/numerical_differentiation.ipynb b/tutorials/module_3/notebook_3/numerical_differentiation.ipynb
new file mode 100644
index 0000000..0892554
--- /dev/null
+++ b/tutorials/module_3/notebook_3/numerical_differentiation.ipynb
@@ -0,0 +1,140 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "d66e2b4b-047b-4670-897d-7877d27a1597",
+ "metadata": {},
+ "source": [
+ "# Numerical Differentiation\n",
+ "\n",
+ "Finding a derivative of tabular data can be done using a finite\n",
+ "difference. Here we essentially pick two points on a function or a set\n",
+ "of data points and calculate the slope from there. Let’s imagine a\n",
+ "domain $x$ as a vector such that $\\vec{x}$ =\n",
+ "$\\pmatrix{x_0, x_1, x_2, ...}$. Then we can use the following methods to\n",
+ "approximate derivatives\n",
+ "\n",
+ "## Forward Difference\n",
+ "\n",
+ "Uses the point at which we want to find the derivative and a point\n",
+ "forwards on the line. $$\n",
+ "f'(x_i) = \\frac{f(x_{i+1})-f(x_i)}{x_{i+1}-x_i}\n",
+ "$$ *Hint: Consider what happens at the last point.*"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "id": "d2fe3ad1-8af0-499a-8954-41a88a49b834",
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "IndexError",
+ "evalue": "index 99 is out of bounds for axis 0 with size 99",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)",
+ "Cell \u001b[0;32mIn[2], line 10\u001b[0m\n\u001b[1;32m 6\u001b[0m y \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m34\u001b[39m \u001b[38;5;241m*\u001b[39m np\u001b[38;5;241m.\u001b[39mexp(\u001b[38;5;241m3\u001b[39m \u001b[38;5;241m*\u001b[39m x)\n\u001b[1;32m 8\u001b[0m dydx \u001b[38;5;241m=\u001b[39m (y[\u001b[38;5;241m1\u001b[39m:] \u001b[38;5;241m-\u001b[39m y[:\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m]) \u001b[38;5;241m/\u001b[39m (x[\u001b[38;5;241m1\u001b[39m:] \u001b[38;5;241m-\u001b[39m x[:\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m])\n\u001b[0;32m---> 10\u001b[0m dydx[\u001b[38;5;28mlen\u001b[39m(y)]\u001b[38;5;241m=\u001b[39mdydx[\u001b[38;5;28mlen\u001b[39m(dydx)]\n\u001b[1;32m 12\u001b[0m \u001b[38;5;66;03m# Plot the function\u001b[39;00m\n\u001b[1;32m 13\u001b[0m plt\u001b[38;5;241m.\u001b[39mplot(x, y, label\u001b[38;5;241m=\u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m$y(x)$\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
+ "\u001b[0;31mIndexError\u001b[0m: index 99 is out of bounds for axis 0 with size 99"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "import matplotlib.pyplot as plt\n",
+ "\n",
+ "# Initiate vectors\n",
+ "x = np.linspace(0, 2, 100) \n",
+ "y = 34 * np.exp(3 * x)\n",
+ "\n",
+ "dydx = (y[1:] - y[:-1]) / (x[1:] - x[:-1])\n",
+ "\n",
+ "dydx[len(y)]=dydx[len(dydx)]\n",
+ "\n",
+ "# Plot the function\n",
+ "plt.plot(x, y, label=r'$y(x)$')\n",
+ "plt.plot(x, dydx, label=r'$\\frac{dy}{dx}$')\n",
+ "plt.xlabel('x')\n",
+ "plt.ylabel('y')\n",
+ "plt.title('Plot of $34e^{3x}$')\n",
+ "plt.grid(True)\n",
+ "plt.legend()\n",
+ "plt.show()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "a54ad04f-05e5-4589-a633-d6dea2a5acfc",
+ "metadata": {},
+ "source": [
+ "## Backwards Difference\n",
+ "\n",
+ "Uses the point at which we want to find $$\n",
+ "f'(x_i) = \\frac{f(x_{i})-f(x_{i-1})}{x_i - x_{i-1}}\n",
+ "$$"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "415d0b3c-a70d-48ef-93ad-6e827127b222",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "dydx = (y[1:] - y[:-1]) / (x[1:] - x[:-1])\n",
+ "\n",
+ "# Plot the function\n",
+ "plt.plot(x, y, label=r'$y(x)$')\n",
+ "plt.plot(x, dydx, label=b'$/frac{dy}{dx}$')\n",
+ "plt.xlabel('x')\n",
+ "plt.ylabel('y')\n",
+ "plt.title('Plot of $34e^{3x}$')\n",
+ "plt.grid(True)\n",
+ "plt.legend()\n",
+ "plt.show()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "21c87595-add2-4f7a-8d10-2da3b4284e02",
+ "metadata": {},
+ "source": [
+ "## Central Difference\n",
+ "\n",
+ "$$\n",
+ "f'(x_i) = \\frac{f(x_{i+1})-f(x_{i-1})}{x_{i+1}-x_{i-1}}\n",
+ "$$"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "6a67e63c-9516-415d-87d6-97d9d986ba33",
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "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.13.2"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
diff --git a/tutorials/module_3/notebook_3/numerical_integration.ipynb b/tutorials/module_3/notebook_3/numerical_integration.ipynb
new file mode 100644
index 0000000..1638ad5
--- /dev/null
+++ b/tutorials/module_3/notebook_3/numerical_integration.ipynb
@@ -0,0 +1,27 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Midpoint Method\n",
+ "\n",
+ "## Trapezoidal Method\n",
+ "\n",
+ "## Romberg Integration\n",
+ "\n",
+ "## Gaussian Integration\n",
+ "\n",
+ "## Simpson’s Rule\n",
+ "\n",
+ "### Simpsons 1/3\n",
+ "\n",
+ "### Simpsons 3/8"
+ ],
+ "id": "81ed366c-8dc9-4d6c-9a5e-36a28f7811b5"
+ }
+ ],
+ "nbformat": 4,
+ "nbformat_minor": 5,
+ "metadata": {}
+}
diff --git a/tutorials/module_3/notebook_3/numerical_methods.ipynb b/tutorials/module_3/notebook_3/numerical_methods.ipynb
new file mode 100644
index 0000000..e5bf7df
--- /dev/null
+++ b/tutorials/module_3/notebook_3/numerical_methods.ipynb
@@ -0,0 +1,52 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Numerical Methods\n",
+ "\n",
+ "Engineering\n",
+ "\n",
+ "## What is a numerical method?\n",
+ "\n",
+ "Numerical methods are techniques that transform mathematical problems\n",
+ "into forms that can be solved using arithmetic and logical operations.\n",
+ "Because digital computers excel at these computations, numerical methods\n",
+ "are often referred to as computer mathematics.\n",
+ "\n",
+ "## Numerical Differentiation\n",
+ "\n",
+ "Forwards difference Backwards difference Central Difference method [Read\n",
+ "More](https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter20.00-Numerical-Differentiation.html)\n",
+ "\n",
+ "## Roots and Optimization\n",
+ "\n",
+ "Incremental Search Bisection Modified Secant Newton-Raphson\n",
+ "\n",
+ "## System of Equations\n",
+ "\n",
+ "Guassian Method LU Decomposition\n",
+ "\n",
+ "## Numerical Integration\n",
+ "\n",
+ "Midpoint Trapezoidal Romberg Gaussian Simpson’s Rule\n",
+ "\n",
+ "[Read\n",
+ "More](https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter21.00-Numerical-Integration.html)\n",
+ "\n",
+ "## Numerical Solutions of Ordinary Differential Equations\n",
+ "\n",
+ "Euler’s Method - Forward - Backwards\n",
+ "\n",
+ "Runge-Kutte\n",
+ "\n",
+ "[ReadMore](https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter22.00-ODE-Initial-Value-Problems.html)"
+ ],
+ "id": "508fb71a-8f30-4cb3-88f8-28b45a334596"
+ }
+ ],
+ "nbformat": 4,
+ "nbformat_minor": 5,
+ "metadata": {}
+}
diff --git a/tutorials/module_3/notebook_3/ode.ipynb b/tutorials/module_3/notebook_3/ode.ipynb
new file mode 100644
index 0000000..a343f4f
--- /dev/null
+++ b/tutorials/module_3/notebook_3/ode.ipynb
@@ -0,0 +1,23 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Numerical Solutions of Ordinary Differential Equations\n",
+ "\n",
+ "## Euler’s Method\n",
+ "\n",
+ "### Forwards Eulers\n",
+ "\n",
+ "### Backwards Eulers\n",
+ "\n",
+ "## Runge-Kutta"
+ ],
+ "id": "4c1220ef-f6ce-43a7-9017-6c22fc8fd4af"
+ }
+ ],
+ "nbformat": 4,
+ "nbformat_minor": 5,
+ "metadata": {}
+}
diff --git a/tutorials/module_3/notebook_3/roots_optimization.ipynb b/tutorials/module_3/notebook_3/roots_optimization.ipynb
new file mode 100644
index 0000000..3e764f2
--- /dev/null
+++ b/tutorials/module_3/notebook_3/roots_optimization.ipynb
@@ -0,0 +1,25 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Root Finding Methods\n",
+ "\n",
+ "Root Finding Methods or non-linear equation solvers.\n",
+ "\n",
+ "## Incremental Search\n",
+ "\n",
+ "## Bisection\n",
+ "\n",
+ "## Modified Secant\n",
+ "\n",
+ "## Newton-Raphson"
+ ],
+ "id": "9483ba01-3002-4544-9286-e134b3d2538b"
+ }
+ ],
+ "nbformat": 4,
+ "nbformat_minor": 5,
+ "metadata": {}
+}