From f2b0832dd88330c3efa7959938587e3c65e32288 Mon Sep 17 00:00:00 2001 From: eggy Date: Tue, 7 Nov 2023 13:51:46 -0500 Subject: [PATCH] ece204: add derivatives --- docs/2a/ece204.md | 88 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/docs/2a/ece204.md b/docs/2a/ece204.md index 9f59b55..9de59df 100644 --- a/docs/2a/ece204.md +++ b/docs/2a/ece204.md @@ -84,3 +84,91 @@ $$\boxed{f(x)=b_0+b_1(x-x_0)+b_2(x-x_0)(x-x_1)}$$ $$ b_2=\frac{\frac{f(x_2)-f(x_1)}{x_2-x_1}-\frac{f(x_1)-f(x_0)}{x_1-x_0}}{x_2-x_0} $$ + +## Derivatives + +Derivatives are estimated based on first principles: + +$$f'(x)=\frac{f(x+h)-f(x)}{h}$$ + +### Derivatives of continuous functions + +At a desired $x$ for $f'(x)$: + +1. Choose an arbitrary $h$ +2. Calculate derivative via first principles +3. Shrink $h$ and recalculate derivative +4. If the answer is drastically different, repeat step 3 + +### Derivatives of discrete functions + +Guesses are made based on the average slope between two points. + +$$f'(x_i)=\frac{f(x_{i+1})-f(x_i)}{x_{i+1}-x_i}$$ + +### Divided differences + +- Using the next term, or a $\Delta x > 0$ indicates a **forward divided difference (FDD)**. +- Using the previous term, or a $\Delta x < 0$ indicates a **backward divided difference (BDD)**. + +The **central divided difference** averages both if $h$ or $\Delta x$ of the forward and backward DDs are equal. + +$$f'(x)=CDD=\frac{f(x+h)-f(x-h)}{2h}$$ + +### Higher order derivatives + +Taking the Taylor expansion of the function or discrete set and then expanding it as necessary can return any order of derivative. This also applies for $x-h$ if positive and negative are alternated. + +$$f(x+h)=f(x)+f'(x)h+\frac{f''(x)}{2!}h^2+\frac{f'''(x)}{3!}h^3$$ + +!!! example + To find second order derivatives: + + \begin{align*} + f''(x)&=\frac{2f(x+h)-2f(x)-2f'(x)h}{h^2} \\ + &=\frac{2f(x+h)-2f(x)-(f(x+h)-f(x-h))}{h^2} \\ + &=\frac{f(x+h)-2f(x)+f(x-h)}{h^2} + \end{align*} + +!!! example + $f''(3)$ if $f(x)=2e^{1.5x}$ and $h=0.1$: + + \begin{align*} + f''(3)&=\frac{f(3.1)-2\times2f(3)+f(2.9)}{0.1^2} \\ + &=405.08 + \end{align*} + +For discrete data: + +- If the desired point does not exist, differentiating the surrounding points to create a polynomial interpolation of the derivative may be close enough. + +!!! example + | t | 0 | 10 | 15 | 20 | 22.5 | 30 | + | --- | --- | --- | --- | --- | --- | --- | + | v(t) | 0 | 227.04 | 362.78 | 517.35 | 602.47 | 901.67 | + + $v'(16)$ with FDD: + + Using points $t=15,t=20$: + + \begin{align*} + v'(x)&=\frac{f(x+h)-f(x)}{h} \\ + &=\frac{f(15+5)-f(15)}{5} \\ + &=\frac{517.35-362.78}{5} \\ + &=30.914 + \end{align*} + + $v'(16)$ with Newton's first-order interpolation: + + \begin{align*} + v(t)&=v(15)+\frac{v(20)-v(15)}{20-15}(t-15) \\ + &=362.78+30.914(t-15) \\ + &=-100.93+30.914t \\ + v'(t)&=\frac{v(t+h)-v(t)}{2h} \\ + &=\frac{v(16.1)-v(15.9)}{0.2} \\ + &=30.914 + \end{align*} + +- If the spacing is not equal (to make DD impossible), again creating an interpolation may be close enough. +- If data is noisy, regressing and then solving reduces random error. +