Talk:Numerical Analysis/Differentiation/Examples

Two Variables
By Taylor's theorem for real functions of two variables,

$$f(x_0 + x, y_0 + y) = f(x_0, y_0) + x \frac{df}{dx}(x_0, y_0) + y \frac{df}{dy}(x_0, y_0) + \frac{x^2}{2} \frac{d^2f}{dx^2}(x_0, y_0) + \frac{y^2}{2} \frac{d^2f}{dy^2}(x_0, y_0) + x y \frac{d}{dy}\frac{df}{dx}(x_0, y_0) + O(x^3) + O(y^3)$$

So

$$c_1 f(x_0 + h, y_0) + c_2 f(x_0 - h, y_0) + c_3 f(x_0, y_0 + h) + c_4 f(x_0, y_0 - h) = (c_1 + c_2 + c_3 + c_4) f(x_0, y_0) + h\left((c_1 + c_2)\frac{df}{dx}(x_0, y_0) + (c_3 + c_4)\frac{df}{dy}(x_0, y_0)\right) + \frac{h^2}{2} \left((c_1 + c_2) \frac{d^2f}{dx^2}(x_0, y_0) + (c_3 + c_4)\frac{d^2f}{dy^2}(x_0, y_0)\right) + O(h^3)$$ Nm160111 (talk) 02:29, 26 November 2012 (UTC)

Mostly Generalized Method
Too complex for examples, but saves work when making them.

By Taylor's theorem,

$$y(x_0 + a) = y(x_0) + a y'(x_0) + a^2 \frac{y(x_0)}{2} + a^3 \frac{y'(x_0)}{6} + a^4 \frac{y^{(4)}(x_0)}{24} + a^5 \frac{y^{(5)}(x_0)}{120} + ... + O(a^{k+1})$$

So

$$\sum_{i=1}^n c_i y(x_0 + b_i h) = y(x_0)\sum_{i=1}^n c_i + h y'(x_0) \sum_{i=1}^n c_i b_i + h^2\frac{y(x_0)}{2}\sum_{i=1}^n c_i b_i^2 + h^3 \frac{y'(x_0)}{6}\sum_{i=1}^n c_i b_i^3 + ... + h^{k} \frac{y^{(5)}(x_0)}{120}\sum_{i=1}^n c_i b_i^{k} + O(h^{k+1})$$

Which we can rearrange as

$$y'(x_0) \sum_{i=1}^n c_i b_i = \frac{\sum_{i=1}^n c_i y(x_0 + b_i h)}{h} - \frac{y(x_0)}{h}\sum_{i=1}^n c_i - h\frac{y(x_0)}{2}\sum_{i=1}^n c_i b_i^2 - h^2 \frac{y'(x_0)}{6}\sum_{i=1}^n c_i b_i^3 - ... - h^{k-1} \frac{y^{(5)}(x_0)}{120}\sum_{i=1}^n c_i b_i^{k} + O(h^k)$$

Given this, we now attempt to choose coefficients $$b_i$$ and $$c_i$$ such that

$$y'(x_0) = \frac{\sum_{i=1}^n c_i y(x_0 + b_i h)}{h} + O(h^k)$$

This can be done by solving the following system of $$k+1$$ equations in $$2n$$ unknowns:

$$1 = \sum_{i=1}^n c_i b_i$$

$$0 = \sum_{i=1}^n c_i$$

$$0 = \sum_{i=1}^n c_i b_i^2$$

$$...$$

$$0 = \sum_{i=1}^n c_i b_i^{k}$$

By setting all $$b_i$$ to be constant, the system of equations may be made linear. Nm160111 (talk) 02:29, 26 November 2012 (UTC)