Question

I'm trying to make a program that will evaluate a Taylor Series (descried below in case you don't know) to the nth order. However, to do this, I need to evaluate a function (which I'm holding in Y1) and its nth derivative. I attempted using nDeriv and saving it as a string into Y2, Y3, etc., but the TI-84 doesn't let me stack more that 2 of those at a time. Does anyone have a way to get around this?

Taylor Series

        O  f^(n)(a)
f(x) ≈  Σ (-------- (x-C)^n)
       n=0    n!

where O is the given order of the series (higher values give a more precise result), f^(n)(a) means "The nth derivative of function f at the value a", and C is a given constant to estimate

Was it helpful?

Solution

Disclaimer: I don't own a TI calculator anymore, and this is based mostly on experimentation I did roughly 7 years ago when I faced a similar problem. The math in the answer should be correct, but I could be mistaken about some minor stuff specific to the calculator.

First, I think I should correct your math. The definition for the Taylor series of a function f(x) at x=a is just

        ∞  f^(n)(a)
f(x) ≈  Σ (-------- (x-a)^n)
       n=0    n!

There's no C involved anywhere (you might have been thinking of the Taylor polynomial reminder theorem, which is a different thing), and the sum is over all nonnegative integers n. Of course, there's no hope for computing an infinite series like this on a TI-84, but we can truncate the series, giving the Nth order Taylor polynomial:

        O  f^(n)(a)
f(x) ≈  Σ (-------- (x-a)^n)
       n=0    n!

This is something that you can actually hope to compute numerically, since the sum is finite. Of course, all you need to do is compute the n-th derivatives for n=0,1,...,O, so from now on I'll focus on that. I think this is what you wanted anyway, but the terminology "Taylor series" always indicates an infinite series, while Taylor polynomial is used when the sum is finite.

nDeriv can not be nested arbitrarily. According to this documentation site, it can be nested one level deep, but I remember that on my earlier model even this wasn't allowed in some cases. However, nDeriv only calculates the derivative numerically anyway, and the formula used is nDeriv(f(t),t,x[,h])) = (f(x+h)-f(x-h))/(2h), where h=0.001 is the default value. You can recursively apply this symbolically to get expressions for higher derivatives:

f^(2)(x)=(f(x+2h)-2f(x)+f(x-2h))/(2h)^2
f^(3)(x)=(f(x+3h)-3f(x+h)+3f(x-h)-f(x-3h))/(2h)^3

and in general:

            n   n    (-1)^m f(x+(n-2m)h)
f^(n)(x) =  Σ (   ) ---------------------
           m=0  m          (2h)^n

Where the weirdly formatted thing inside the sum is the binomial coefficient (n nCr m on the TI-84). This can be computed in TI basic and is equivalent to the final result which you would get if the calculator would let you nest nDeriv arbitrarily (at least until machine precision effects start to become important).

You probably want to play around with h some until you find a good value (and for different order derivatives you may want to use different values of h). Unfortunately, numerical differentiation is naturally hard to do, especially with low precision devices like calculators, because you're subtracting two very close numbers to get a very small number, and dividing by another very small number. For higher order derivatives, things only get worse. I remember that for some simple functions I could get 4 or 5 derivatives before it was just impossible to get anything meaningful because the calculator just doesn't have enough precision.

Incidentally, if you find the above method isn't precise enough, there's a ton of literature on numerical differentiation with better methods than the one laid out above. A good place to start would be the Wikipedia article on finite difference methods, of which the above formula is a (not particularly good) example. No matter what, you're going to run into machine precision issues, but using a more sophisticated method will at least raise the accuracy until machine precision effects start to be important.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top