From 985812d89a71504de3af779a5332ad817394fdea Mon Sep 17 00:00:00 2001 From: Christian Kolset Date: Wed, 10 Sep 2025 17:23:15 -0600 Subject: Updated roots --- tutorials/module_3/2_roots_optimization.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tutorials/module_3/2_roots_optimization.md b/tutorials/module_3/2_roots_optimization.md index 3d126e0..a97e7d2 100644 --- a/tutorials/module_3/2_roots_optimization.md +++ b/tutorials/module_3/2_roots_optimization.md @@ -136,6 +136,10 @@ plt.title("Data with multiple roots") plt.legend() plt.show() ``` + +## False Position + + # Open Methods So far we looked at methods that require us to bracket a root before finding it. However, let's think outside of the box and ask ourselves if we can find a root with only 1 guess. Can we improve the our guess by if we have some knowledge of the function itself? The answer - derivatives. @@ -163,13 +167,14 @@ $$ \boxed{x_{i+1} = x_i - \frac{f(x_i)}{f'(x_i)}} $$ ### Assignment 2 -Write a python function called *newtonraphson* which as the following input parameters +From experimental data we extrapolated a function f. Write a python function called *newtonraphson* which as the following input parameters - `f` - function - `df` - first derivative of the function - `x0` - initial guess - `tol` - the tolerance of error That finds the root of the function $f(x)=e^{\left(x-6.471\right)}\cdot1.257-0.2$ and using an initial guess of 8. +Using Recursion ```python def newtonraphson(f, df, x0, tol): # Output of this function is the estimated root of f @@ -180,12 +185,22 @@ def newtonraphson(f, df, x0, tol): else: return newtonraphson(f,df,x0) -f = lambda x:x**2-1.5 -f_prime = labmda x:2*x +f = lambda x: x**2-1.5 +f_prime = labmda x: 2*x ``` +Using Iteration +```python +def newtonraphson(f, df, x0, tol): + for i in +``` + + + ## Modified Secant +A possible issue with the Newton-Raphson method is that we are required to know the derivative of the function we are finding the root for. Sometimes this may be extremely difficult or impossible to find analytically. Thus we can use the modified secant method. + This method uses the finite derivative to guess where the root lies. We can then iterate this guessing process until we're within tolerance. $$ @@ -198,12 +213,13 @@ $$ x_{x+1} = x_i - \frac{f(x_i)(x_{i-1}-x_i)}{f(x_i+\delta x)-f(x_i)} $$ $$ -x_{x+1} = x_i - \frac{f(x_i)\delta_x}{f(x_i+\delta x)-f(x_i)} +x_{x+1} = x_i - \frac{f(x_i)\delta x_i}{f(x_i+\delta x)-f(x_i)} $$ ## Issues with open methods -Diverging guesses + +Open methods may also have it's problems. Let's consider the following function: $f(x)=3.2*tan^{-1}(x-4.3)$ if we were to apply the Newton-Raphson to find the root of this function we can see that the results diverge. This happens when # Pipe Friction Example -- cgit v1.2.3