diff options
| author | Christian Kolset <christian.kolset@gmail.com> | 2025-04-24 16:25:31 -0600 |
|---|---|---|
| committer | Christian Kolset <christian.kolset@gmail.com> | 2025-04-24 16:25:31 -0600 |
| commit | 652f88728eb91bae1c4f30b63d1fbe60788ea938 (patch) | |
| tree | 65cfe591da183b969885e8c557b1ac5810727ec8 /tutorials/module_3 | |
| parent | 42fca6122f4baf847ec2794b172abbc6a2193407 (diff) | |
Added jupyter notebook converter script. Converts markdown (.md) tutorials to jupyter notebook (.ipynb).
Diffstat (limited to 'tutorials/module_3')
| -rw-r--r-- | tutorials/module_3/notebook_3/non_linear_eqn_solver.ipynb | 130 | ||||
| -rw-r--r-- | tutorials/module_3/notebook_3/supersonic.ipynb | 15 | ||||
| -rw-r--r-- | tutorials/module_3/notebook_3/system_of_equations.ipynb | 15 |
3 files changed, 160 insertions, 0 deletions
diff --git a/tutorials/module_3/notebook_3/non_linear_eqn_solver.ipynb b/tutorials/module_3/notebook_3/non_linear_eqn_solver.ipynb new file mode 100644 index 0000000..5d68cff --- /dev/null +++ b/tutorials/module_3/notebook_3/non_linear_eqn_solver.ipynb @@ -0,0 +1,130 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Solving non-linear equations\n", + "\n", + "## Introduction\n", + "\n", + "## Prerequisites\n", + "\n", + "``` python\n", + "import numpy\n", + "import scipy\n", + "import sympy\n", + "```\n", + "\n", + "## fsolve from SciPy\n", + "\n", + "``` python\n", + "from scipy.optimize import fsolve\n", + "\n", + "def equations(vars):\n", + " x, y = vars\n", + " eq1 = x**2 + y**2 - 25\n", + " eq2 = x**2 - y\n", + " return [eq1, eq2]\n", + "\n", + "initial_guess = [1, 1]\n", + "solution = fsolve(equations, initial_guess)\n", + "print(\"Solution:\", solution)\n", + "```\n", + "\n", + "## root from SciPy\n", + "\n", + "``` python\n", + "from scipy.optimize import root\n", + "\n", + "def equations(vars):\n", + " x, y = vars\n", + " eq1 = x**2 + y**2 - 25\n", + " eq2 = x**2 - y\n", + " return [eq1, eq2]\n", + "\n", + "initial_guess = [1, 1]\n", + "solution = root(equations, initial_guess)\n", + "print(\"Solution:\", solution.x)\n", + "```\n", + "\n", + "## minimize from SciPy\n", + "\n", + "``` python\n", + "from scipy.optimize import minimize\n", + "\n", + "# Define the equations\n", + "def equation1(x, y):\n", + " return x**2 + y**2 - 25\n", + "\n", + "def equation2(x, y):\n", + " return x**2 - y\n", + "\n", + "# Define the objective function for optimization\n", + "def objective(xy):\n", + " x, y = xy\n", + " return equation1(x, y)**2 + equation2(x, y)**2\n", + "\n", + "# Initial guess\n", + "initial_guess = [1, 1]\n", + "\n", + "# Perform optimization\n", + "result = minimize(objective, initial_guess)\n", + "solution_optimization = result.x\n", + "\n", + "print(\"Optimization Method Solution:\", solution_optimization)\n", + "```\n", + "\n", + "## nsolve from SymPy\n", + "\n", + "``` python\n", + "from sympy import symbols, Eq, nsolve\n", + "\n", + "# Define the variables\n", + "x, y = symbols('x y')\n", + "\n", + "# Define the equations\n", + "eq1 = Eq(x**2 + y**2, 25)\n", + "eq2 = Eq(x - y, 0)\n", + "\n", + "# Initial guess for the solution\n", + "initial_guess = [1, 1]\n", + "\n", + "# Use nsolve to find the solution\n", + "solution = nsolve([eq1, eq2], [x, y], initial_guess)\n", + "print(\"Solution:\", solution)\n", + "```\n", + "\n", + "## newton_method from NumPy\n", + "\n", + "``` python\n", + "import numpy as np\n", + "\n", + "def equations(vars):\n", + " x, y = vars\n", + " eq1 = x**2 + y**2 - 25\n", + " eq2 = x**2 - y\n", + " return np.array([eq1, eq2])\n", + "\n", + "def newton_method(initial_guess, tolerance=1e-6, max_iter=100):\n", + " vars = np.array(initial_guess, dtype=float)\n", + " for _ in range(max_iter):\n", + " J = np.array([[2 * vars[0], 2 * vars[1]], [2 * vars[0], -1]])\n", + " F = equations(vars)\n", + " delta = np.linalg.solve(J, -F)\n", + " vars += delta\n", + " if np.linalg.norm(delta) < tolerance:\n", + " return vars\n", + "\n", + "initial_guess = [1, 1]\n", + "solution = newton_method(initial_guess)\n", + "print(\"Solution:\", solution)\n", + "```" + ], + "id": "bc920a9c-8e0c-41dc-ab36-cf3f81515dd5" + } + ], + "nbformat": 4, + "nbformat_minor": 5, + "metadata": {} +} diff --git a/tutorials/module_3/notebook_3/supersonic.ipynb b/tutorials/module_3/notebook_3/supersonic.ipynb new file mode 100644 index 0000000..af78e75 --- /dev/null +++ b/tutorials/module_3/notebook_3/supersonic.ipynb @@ -0,0 +1,15 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Supersonic" + ], + "id": "25de80df-3331-45ed-b288-f17d40bce45f" + } + ], + "nbformat": 4, + "nbformat_minor": 5, + "metadata": {} +} diff --git a/tutorials/module_3/notebook_3/system_of_equations.ipynb b/tutorials/module_3/notebook_3/system_of_equations.ipynb new file mode 100644 index 0000000..20ef9f5 --- /dev/null +++ b/tutorials/module_3/notebook_3/system_of_equations.ipynb @@ -0,0 +1,15 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# System of Equations" + ], + "id": "cc610e14-31e7-459d-81e1-0016e8c06fcd" + } + ], + "nbformat": 4, + "nbformat_minor": 5, + "metadata": {} +} |
