# Lagrange Error Bound

> It's also called the `Lagrange Error Theorem`, or `Taylor's Remainder Theorem`.

To approximate a function more precisely, we'd like to express the function as a **sum of a Taylor Polynomial & a Remainder.**

![image](https://user-images.githubusercontent.com/14041622/42287774-50cf980c-7fea-11e8-8ecb-59c2d9730f02.png) (▲ For `T` is the **Taylor polynomial** with n terms, and `R` is the **Remainder** after n terms.)

[`▲Jump back to review the note on Error estimation Theorem.`](https://github.com/solomonxie/solomonxie.github.io/issues/49#issuecomment-400239322)

[`►Jump over to have practice at Khan academy: Lagrange Error Bound.`](https://www.khanacademy.org/math/ap-calculus-bc/bc-series/modal/e/taylor-polynomial-approximation)

The tricky part of that expression is to "preset" the accuracy of the `Error`, aka. the `Remainder`.

For **bounding** the `Error`, out strategy is to apply the `Lagrange Error Bound` theorem.

Simply saying, the theorem is:

*   If a function's **ALL DERIVATIVES** are bounded by **a number** over the interval `(C, x)`:

    ![image](https://user-images.githubusercontent.com/14041622/42287639-c4fdba20-7fe9-11e8-99dc-c3fd033459ed.png)

    (▲ for `C` is the centre of approximation)
*   where the max value of **all derivatives** of the function is:

    ![image](https://user-images.githubusercontent.com/14041622/42287679-e5c2299e-7fe9-11e8-931d-6303f03cbeb1.png)

    (▲ for `z` is any value between `C` and `x` makes the derivative to the **max**)

    (▲ and note that: the **input** has to be `n+1` )
*   then the **function's Remainder** MUST satisfy this theorem:

    ![image](https://user-images.githubusercontent.com/14041622/42278902-bc06c364-7fce-11e8-899f-a486f516ecc1.png)

## Example

![image](https://user-images.githubusercontent.com/14041622/42278785-72735c3a-7fce-11e8-8ecf-50a11b37a51e.png) Solve:

* This problem is to approximate a function with Taylor Polynomial.
*   To do so, we're to set use the `Error estimation` method, which first to set up the equation:

    ![image](https://user-images.githubusercontent.com/14041622/42279513-9350909c-7fd0-11e8-8d3c-8ebf088665c5.png)
*   In this case, it is:

    ![image](https://user-images.githubusercontent.com/14041622/42279412-4700f1c8-7fd0-11e8-9e21-0b07de93cd0e.png)
* Since it's only asking for the `error bound`, so we **only focus** on the Error `Rn`.
*   We want to apply the `Lagrange Error Bound Theorem`, and bound it to `0.001`:

    ![image](https://user-images.githubusercontent.com/14041622/42279497-859ddc34-7fd0-11e8-9b29-467cc3253085.png)
* For those **unknowns** variables in the theorem, we know that:
  * The approximation is centred at `1.5π`, so `C = 1.5π`.
  * The input of function is `1.3π`, so `x = 1.3π`.
  * For The `M` value, because **all the derivatives** of the function `cos(x)`, are bounded to 1 even **without an interval** , so let's say the max value `M = 1`.
*   Therefore, the formula of this theorem becomes:

    ![image](https://user-images.githubusercontent.com/14041622/42279703-423dd696-7fd1-11e8-8397-a176d420a69a.png)
*   Unfortunately, at this moment we don't have easier method to solve for `n` except trying some numbers in:

    ![image](https://user-images.githubusercontent.com/14041622/42279842-a358b0cc-7fd1-11e8-94a4-c6d8697412fa.png)
* We could see that, with the degree gets larger and larger, the `Error` becomes smaller and smaller.
* Only until `n=4`, which means the `4th derivative`, the `Error` is less than `0.001`.
* So the answer is `4th derivative`.

## Example

![image](https://user-images.githubusercontent.com/14041622/42285625-c4ce0746-7fe2-11e8-8e96-5043b22f65cf.png) Solve:

*   Same with the problem above, we want to apply the `Lagrange Error Bound Theorem`, and bound it to `0.001`:

    ![image](https://user-images.githubusercontent.com/14041622/42279497-859ddc34-7fd0-11e8-9b29-467cc3253085.png)
* For those **unknowns** variables in the theorem, we know that:
  * The approximation is centred at `0` because it's told as a `Maclaurin Series` , so `C = 0`.
  * The input of function is `-0.95`, so `x = -0.95`.
  * The interval is (C, x) or (x, C), which is `(-0.95, 0)`  in this case.
* For The `M` value, since all the derivatives of `eˣ` is just `eˣ`, and `eˣ`  is unbounded at all, so we're to examine the Max value over the interval `(-0.95, 0)`
*   With the help from `Desmos Calculator`, we know that over the interval `(-0.95, 0)`, the max value of `eˣ` is `e⁰ = 1`:

    ![image](https://user-images.githubusercontent.com/14041622/42287179-f78b7024-7fe7-11e8-9c9f-9f3a7d580301.png)
* So boundary is `M = 1`.
*   Therefore, the formula of this theorem becomes:

    ![image](https://user-images.githubusercontent.com/14041622/42285962-c35262b2-7fe3-11e8-9862-a95cc085d15c.png)
*   In this case, we need to try some numbers for `n` to get the desired value:

    ![image](https://user-images.githubusercontent.com/14041622/42286050-1b676380-7fe4-11e8-8f84-ecb0c91da588.png)
* After tried `n=5` and `n=6`, we could see that only until `n=6`, which means the `6th derivative`, the `Error` is less than `0.001`.
* So the answer is `6th derivative`.

## Example

![image](https://user-images.githubusercontent.com/14041622/42288078-d5ba3de6-7feb-11e8-934d-9ebae98d116f.png) Solve:

*   Same with the problem above, we want to apply the `Lagrange Error Bound Theorem`, and bound it to `0.001`:

    ![image](https://user-images.githubusercontent.com/14041622/42279497-859ddc34-7fd0-11e8-9b29-467cc3253085.png)
* For those **unknowns** variables in the theorem, we know that:
  * The approximation is centred at `2`, so `C = 2`.
  * The input of function is `2.5`, so `x = 2.5`.
  * The interval then is `(2, 2.5)`.
*   For the `M` value, it's not easy to figure out, but we've been told the formula for derivative.

    ![image](https://user-images.githubusercontent.com/14041622/42288599-fe6e5b80-7fed-11e8-8066-456535489726.png)
* So the expression for `M` would be:
*   Let's directly plug in the `M` expression into the Remainder:

    ![image](https://user-images.githubusercontent.com/14041622/42289216-e1d10362-7ff0-11e8-970e-6cff6b9c507f.png)
*   With the help from `Desmos grapher` we know that when within the interval `2≤ z ≤ 2.5`, that `z=2` makes the formula to the max:

    ![image](https://user-images.githubusercontent.com/14041622/42289271-34ce8788-7ff1-11e8-94b3-b6cb43bb2651.png)
*   So let's set the inequality:

    ![image](https://user-images.githubusercontent.com/14041622/42289259-1c7ffe50-7ff1-11e8-917f-8841f2585e5d.png)
* After trying out some number for `n`, we get that `n ≥ 3`.
