summaryrefslogtreecommitdiff
path: root/tutorials/module_3/1_numerical_differentiation.md
diff options
context:
space:
mode:
Diffstat (limited to 'tutorials/module_3/1_numerical_differentiation.md')
-rw-r--r--tutorials/module_3/1_numerical_differentiation.md41
1 files changed, 29 insertions, 12 deletions
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,7 +11,8 @@ 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}
@@ -19,14 +20,21 @@ $$
*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