From 18eb6dbfa545cdbb69103e312ccb0992d1b20b00 Mon Sep 17 00:00:00 2001 From: Christian Kolset Date: Fri, 12 Sep 2025 17:24:40 -0600 Subject: Worked on module 3 --- tutorials/module_3/1_numerical_differentiation.md | 41 ++++++++++++++++------- 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'tutorials/module_3/1_numerical_differentiation.md') diff --git a/tutorials/module_3/1_numerical_differentiation.md b/tutorials/module_3/1_numerical_differentiation.md index aa45c3a..68e0953 100644 --- a/tutorials/module_3/1_numerical_differentiation.md +++ b/tutorials/module_3/1_numerical_differentiation.md @@ -11,22 +11,30 @@ s = 34 * np.exp(3 * t) Then we can use the following methods to approximate the definitive derivatives as follows. -## Forward Difference +## Finite Difference +### Forward Difference Uses the point at which we want to find the derivative and a point forwards in the array. $$ f'(x_i) = \frac{f(x_{i+1})-f(x_i)}{x_{i+1}-x_i} $$ *Note: If we apply this to an array, consider what happens at the last point.* +```python +for s in t: + ds_dt = f(x+) +``` + + + ```python # Forward difference using python arrays -dsdt = (y[1:] - y[:-1]) / (x[1:] - x[:-1]) +dsdt = (s[1:] - s[:-1]) / (t[1:] - t[:-1]) import matplotlib.pyplot as plt # Plot the function -plt.plot(x, s, label=r'$y(x)$') -plt.plot(x, dsdt, label=b'$/frac{ds}{dt}$') +plt.plot(t, s, label=r'$s(t)$') +plt.plot(t, dsdt, label=b'$/frac{ds}{dt}$') plt.xlabel('Time (t)') plt.ylabel('Displacement (s)') plt.title('Plot of $34e^{3t}$') @@ -36,7 +44,7 @@ plt.show() ``` -## Backwards Difference +### Backwards Difference Uses the point at which we want to find and the previous point in the array. $$ f'(x_i) = \frac{f(x_{i})-f(x_{i-1})}{x_i - x_{i-1}} @@ -44,23 +52,32 @@ $$ ```python -dsdt = (y[1:] - y[:-1]) / (x[1:] - x[:-1]) +dsdt = (s[1:] - s[:-1]) / (t[1:] - t[:-1]) # Plot the function -plt.plot(x, y, label=r'$y(x)$') -plt.plot(x, dydx, label=b'$/frac{ds}{dt}$') -plt.xlabel('x') -plt.ylabel('y') -plt.title('Plot of $34e^{3x}$') +plt.plot(t, s, label=r'$s(t)$') +plt.plot(t, dydx, label=b'$/frac{ds}{dt}$') + +plt.xlabel('Time (t)') +plt.ylabel('Displacement (s)') +plt.title('Plot of $34e^{3t}$') plt.grid(True) plt.legend() plt.show() ``` -## Central Difference +Try plotting both forward and backwards + +### Central Difference $$ f'(x_i) = \frac{f(x_{i+1})-f(x_{i-1})}{x_{i+1}-x_{i-1}} $$ +--- +# Advanced Derivatives +## High-Accuracy Differentiation Formulas +## Richardson Extrapolation +## Derivative of Unequally Spaced Data +## Partial Derivatives -- cgit v1.2.3