summaryrefslogtreecommitdiff
path: root/tutorials/module_2
diff options
context:
space:
mode:
authorChristian Kolset <christian.kolset@gmail.com>2025-04-29 18:32:22 -0600
committerChristian Kolset <christian.kolset@gmail.com>2025-04-29 18:32:22 -0600
commit098fb4a08ca946ed2c8aa234f1a7129abde9fde0 (patch)
tree7b99a3d44742db9c6a63d497a13709f115855398 /tutorials/module_2
parent62e500a9b73c4894a57ce96f47c5c2c290513537 (diff)
Updated Readme Admin section for meeting 2025-24-25
Diffstat (limited to 'tutorials/module_2')
-rw-r--r--tutorials/module_2/intro_to_numerical_methods.md41
-rw-r--r--tutorials/module_2/non_linear_eqn_solver.md117
2 files changed, 117 insertions, 41 deletions
diff --git a/tutorials/module_2/intro_to_numerical_methods.md b/tutorials/module_2/intro_to_numerical_methods.md
deleted file mode 100644
index 6791aff..0000000
--- a/tutorials/module_2/intro_to_numerical_methods.md
+++ /dev/null
@@ -1,41 +0,0 @@
-# Numerical Methods
-Engineering
-
-## What is a numerical method?
-Numerical methods are techniques that transform mathematical problems into forms that can be solved using arithmetic and logical operations. Because digital computers excel at these computations, numerical methods are often referred to as computer mathematics.
-
-
-## Numerical Differentiation
-Forwards difference
-Backwards difference
-
-[Read More](https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter20.00-Numerical-Differentiation.html)
-
-## Roots and Optimization
-Incremental Search
-Bisection
-Modified Secant
-Newton-Raphson
-
-
-## Numerical Integration
-
-Trapezoidal
-
-Simpson's Rule
-
-[Read More](https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter21.00-Numerical-Integration.html)
-
-
-## Numerical Solutions of Ordinary Differential Equations
-
-Euler's Method
-- Forward
-- Backwards
-
-Runge-Kutta Method
-
-[Read More](https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter22.00-ODE-Initial-Value-Problems.html)
-
-
-
diff --git a/tutorials/module_2/non_linear_eqn_solver.md b/tutorials/module_2/non_linear_eqn_solver.md
new file mode 100644
index 0000000..6d1ded3
--- /dev/null
+++ b/tutorials/module_2/non_linear_eqn_solver.md
@@ -0,0 +1,117 @@
+# Solving non-linear equations
+
+## Introduction
+
+
+## Prerequisites
+
+```python
+import numpy
+import scipy
+import sympy
+```
+
+
+## fsolve from SciPy
+
+```python
+from scipy.optimize import fsolve
+
+def equations(vars):
+ x, y = vars
+ eq1 = x**2 + y**2 - 25
+ eq2 = x**2 - y
+ return [eq1, eq2]
+
+initial_guess = [1, 1]
+solution = fsolve(equations, initial_guess)
+print("Solution:", solution)
+```
+
+## root from SciPy
+```python
+from scipy.optimize import root
+
+def equations(vars):
+ x, y = vars
+ eq1 = x**2 + y**2 - 25
+ eq2 = x**2 - y
+ return [eq1, eq2]
+
+initial_guess = [1, 1]
+solution = root(equations, initial_guess)
+print("Solution:", solution.x)
+```
+
+
+## minimize from SciPy
+```python
+from scipy.optimize import minimize
+
+# Define the equations
+def equation1(x, y):
+ return x**2 + y**2 - 25
+
+def equation2(x, y):
+ return x**2 - y
+
+# Define the objective function for optimization
+def objective(xy):
+ x, y = xy
+ return equation1(x, y)**2 + equation2(x, y)**2
+
+# Initial guess
+initial_guess = [1, 1]
+
+# Perform optimization
+result = minimize(objective, initial_guess)
+solution_optimization = result.x
+
+print("Optimization Method Solution:", solution_optimization)
+
+```
+
+## nsolve from SymPy
+```python
+from sympy import symbols, Eq, nsolve
+
+# Define the variables
+x, y = symbols('x y')
+
+# Define the equations
+eq1 = Eq(x**2 + y**2, 25)
+eq2 = Eq(x - y, 0)
+
+# Initial guess for the solution
+initial_guess = [1, 1]
+
+# Use nsolve to find the solution
+solution = nsolve([eq1, eq2], [x, y], initial_guess)
+print("Solution:", solution)
+```
+
+## newton_method from NumPy
+
+```python
+import numpy as np
+
+def equations(vars):
+ x, y = vars
+ eq1 = x**2 + y**2 - 25
+ eq2 = x**2 - y
+ return np.array([eq1, eq2])
+
+def newton_method(initial_guess, tolerance=1e-6, max_iter=100):
+ vars = np.array(initial_guess, dtype=float)
+ for _ in range(max_iter):
+ J = np.array([[2 * vars[0], 2 * vars[1]], [2 * vars[0], -1]])
+ F = equations(vars)
+ delta = np.linalg.solve(J, -F)
+ vars += delta
+ if np.linalg.norm(delta) < tolerance:
+ return vars
+
+initial_guess = [1, 1]
+solution = newton_method(initial_guess)
+print("Solution:", solution)
+``` \ No newline at end of file