Approximating function derivatives
|
01-26-2024, 08:33 AM
Post: #5
|
|||
|
|||
RE: Approximating function derivatives
Following Albert's approach we can disentangle the calculation of odd and even derivatives.
\( \begin{align} f_{+1} &= f(x_0 + h) &= f(x_0) + {f}'(x_0) h + \frac{1}{2}{f}''(x_0) h^2 + \frac{1}{6}{f}'''(x_0) h^3 + \mathcal{O}(h^4) \\ \\ f_{-1} &= f(x_0 - h) &= f(x_0) - {f}'(x_0) h + \frac{1}{2}{f}''(x_0) h^2 - \frac{1}{6}{f}'''(x_0) h^3 + \mathcal{O}(h^4) \\ \\ f_{+2} &= f(x_0 + 2h) &= f(x_0) + 2{f}'(x_0) h + 2{f}''(x_0) h^2 + \frac{4}{3}{f}'''(x_0) h^3 + \mathcal{O}(h^4) \\ \\ f_{-2} &= f(x_0 - 2h) &= f(x_0) - 2{f}'(x_0) h + 2{f}''(x_0) h^2 - \frac{4}{3}{f}'''(x_0) h^3 + \mathcal{O}(h^4) \\ \\ \end{align} \) Even derivatives \( \begin{align} f_{+1} + f_{-1} &= 2f(x_0) + {f}''(x_0) h^2 + \mathcal{O}(h^4) \\ f_{+2} + f_{-2} &= 2f(x_0) + 4{f}''(x_0) h^2 + \mathcal{O}(h^4) \\ \end{align} \) Or: \( \begin{bmatrix} f_{+1} + f_{-1} \\ f_{+2} + f_{-2} \\ \end{bmatrix} \approx \begin{bmatrix} 2 & 1 \\ 2 & 4 \\ \end{bmatrix} \cdot \begin{bmatrix} f(x_0) \\ {f}''(x_0) h^2 \\ \end{bmatrix} \) This leads to: \( \begin{bmatrix} f(x_0) \\ {f}''(x_0) h^2 \\ \end{bmatrix} \approx \begin{bmatrix} \frac{2}{3} & - \frac{1}{6} \\ - \frac{1}{3} & \frac{1}{3} \\ \end{bmatrix} \cdot \begin{bmatrix} f_{+1} + f_{-1} \\ f_{+2} + f_{-2} \\ \end{bmatrix} \) Odd derivatives \( \begin{align} f_{+1} - f_{-1} &= 2{f}'(x_0) h + \frac{1}{3}{f}'''(x_0) h^3 + \mathcal{O}(h^4) \\ f_{+2} - f_{-2} &= 4{f}'(x_0) h + \frac{8}{3}{f}'''(x_0) h^3 + \mathcal{O}(h^4) \\ \end{align} \) Or: \( \begin{bmatrix} f_{+1} - f_{-1} \\ f_{+2} - f_{-2} \\ \end{bmatrix} \approx \begin{bmatrix} 2 & \frac{1}{3} \\ 4 & \frac{8}{3} \\ \end{bmatrix} \cdot \begin{bmatrix} {f}'(x_0) h \\ {f}'''(x_0) h^3 \\ \end{bmatrix} \) This leads to: \( \begin{bmatrix} {f}'(x_0) h \\ {f}'''(x_0) h^3 \\ \end{bmatrix} \approx \begin{bmatrix} \frac{2}{3} & - \frac{1}{12} \\ - 1 & \frac{1}{2} \\ \end{bmatrix} \cdot \begin{bmatrix} f_{+1} - f_{-1} \\ f_{+2} - f_{-2} \\ \end{bmatrix} \) This allows to optimise the program for the HP-42S a bit: Code: 00 { 103-Byte Prgm } Registers R00: \(x_0\) R01: \(h\) R02: \(f_{+1} + f_{-1}\) R03: \(f_{+1} - f_{-1}\) R04: \(f_{+2} + f_{-2}\) R05: \(f_{+2} - f_{-2}\) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)