# Taylor Series of piecewise functions

Discussion in 'Math' started by guitarguy12387, Sep 4, 2008.

1. ### guitarguy12387 Thread Starter Active Member

Apr 10, 2008
359
12
Ok, it has been a while since i have done anything with taylor series/polynomials (i was never that good with them in the first place haha). But i have been given the problem:

Calculate the Taylor series at x=0 of:

f(x) = exp(-1/x) for x>0; 0 for x$\leq$0.

Why is the result interesting?

The part that i am struggling is with is how to approach the problem being that it is a piecewise function. I have calculated the derivatives of the function at x=0. Turns out that they are all undefined for x>0 and 0 for x$\leq$ 0.

I hope someone will be able to point me in the right direction. Thanks in advance.

2. ### Mark44 Well-Known Member

Nov 26, 2007
626
1
For a function f to have a Taylor series at x = a, the function and all of its derivatives must exist at x = a. Your function has a value at x = 0, but none of its derivatives exist there, so it isn't possible to get a Taylor series at x = 0. IOW, there are no constants a0, a1, a2, ... so that a0 + a1*x + a2 * x^2 + ... converges to f. BTW, the Taylor series of a function at x = 0 is called the Maclaurin series for the function.

Are you sure that the problem is to find the Taylor series at x = 0? You could find it for x near 0, like say, at x = 1.

3. ### silvrstring Active Member

Mar 27, 2008
159
0
Hi Mark44. I was also looking at this problem.

If exp(x) ≈ 1 + x + (x^2)/2! + (x^3)/3! + (x^4)/4! + ... +(x^n)/n!

Then by substitution, wouldn't
f(x) = exp(-1/x) ≈ 1 - 1/x + 1/(2!x^2) - 1/(3!x^3) + 1/(4!x^4) - ... + 1/(n!x^n) for |x|>0.

I, too, am curious; It seems to work out on a graph.

4. ### Mark44 Well-Known Member

Nov 26, 2007
626
1
That works for me. As your work shows, there's more than one way to get a series expansion for a particular function.

5. ### silvrstring Active Member

Mar 27, 2008
159
0
But how would this problem be expressed in summation form in relation to its piecewise function.

Do you just declare it for x≠0, and that f(0)=0?

6. ### Mark44 Well-Known Member

Nov 26, 2007
626
1
f(x) = $\sum$ (-1)$^{n}$ / (n! x$^{n}$), x > 0
= 0, x $\leq$= 0

The summation runs from n = 0 to ∞.

I'm trusting that your substitution is correct.

7. ### silvrstring Active Member

Mar 27, 2008
159
0
Yes, I think so. Thanks Mark44.

8. ### guitarguy12387 Thread Starter Active Member

Apr 10, 2008
359
12
Hey guys, thanks for the help. Here it is, copy and pasted:

Problem 3: Let f be the function

f (x) = exp(−1/x) , x > 0
0 , x ≤ 0

Calculate the Taylor series of f at 0 (i.e. the Maclaurin series of f ). Why the result is interesting? (Hints: Show ﬁrst that all derivatives f^(n) of f on the positive real axis are of the form Pn(1/x)exp(−1/x) , where Pn is a polynomial. Use then the facts that Q(1/x)exp(−1/x) → 0 as x → 0 for all polynomials and that f^(n)(0) = lim x →0 f^(n) (x) if f^(n) exists for x = 0 and the limit exists. These facts need not be proven.)

Where f^(n) is the nth derivative of f.

I am a little confused now... your first post says that the taylor series cannot exist because the derivative at 0 does not exist. Makes sense. Than how did you still come up with an expansion in this most recent post? Thanks again for your time.

9. ### silvrstring Active Member

Mar 27, 2008
159
0
guitarguy,

substitution is used to obtain the expansion of the problem.

Here is an example:

f(x) = exp(x^2)
We know that exp(x) ≈ 1 + x + (x^2)/2! + (x^3)/3! + (x^4)/4! +... + (x^n)/n!
To find exp(x^2), we can simply substitute x^2 into x.
If for exp(x), Pn(x)= the above, then
exp(x^2) ≈ Pn(x^2) = 1 + x^2 + ((x^2)^2)/2! + ((x^2)^3)/3! + ((x^2)^4)/4! + ... + ((x^2)^n)/n!
= 1 + x^2 + (x^4)/2! + (x^6)/3! + (x^8)/4! +...+ ((x^2)^n)/n!

So for the expansion of f(x)=exp(-1/x), substitute (-1/x) into Pn(x) of f(x)=exp(x).

I was having trouble figuring out how to write the final summation expression for Pn(x) because my Calc class mainly focused on x>=0. If your limits are -∞ to ∞, you may have to write the expression as a summation from -∞ to 0 plus the expression for the summation from 0 to ∞ because this problem diverges as x approaches 0 from the left. That's why you have to use substitution: Because all of the derivatives of f(x) for x=0 will be 0, and y approaches infinity as x-->0 from the left.

Does that help? If you go to freegraphcalc.com and plug them in, you'll see it works. On paper, though, make sure you declare the conditions (i.e., x(0) = 0).

oops, nevermind...freegraphcalc.com is a broken link.

Last edited: Sep 5, 2008
10. ### guitarguy12387 Thread Starter Active Member

Apr 10, 2008
359
12
Right that makes sense. But, as you said,

And as mark44 mentioned above, that derivatives for this function at x=0 does not exist. So how can you write a correct expansion? (Does not exist because the derivative from the right of zero does not equal the derivative from the left).

11. ### Ratch New Member

Mar 20, 2007
1,068
4
guitarguy12387,

12387? How many of you guitarguys are there?

I don't know, do you?

You mean about x=0, not at x=0. In other words, you want to calculate the Maclaurin series.

We will take it one piece at a time.

How can you say that? Yes, all the derivatives are zero at x=0. The first derivative is exp(-1/x)/x^2 which is certainly defined at x>0. Would you believe that the function and all its derivatives are defined for all real numbers?

As silvrstr pointed out in post #9, for x>0, all you have to do is substitute -1/x into the classic e^x Maclaurin series to get 1-1/x+1/(2*x^2)-1/(6*x^3)+1/(24*x^4)-1/(120*x^5)+1/(720*x^6)-1/(5040*x^7) ... etc. At x=0 or x<0, the function is simply zero.

I am not following this. y does not approach infinity from the left. You defined it as constantly zero for x<0. The function is continuous at x=0, and all its derivatives are defined for all real values.

I'm trying.

Ratch

12. ### Mark44 Well-Known Member

Nov 26, 2007
626
1
That's an excellent question, and one I don't have an answer for at the moment. It bothers me that you can't get the Maclaurin series for the function directly (i.e., as f(0) + f'(0)* x + f''(0) *x^2/2! + ...), but you can get a Maclaurin series by substituting (-1/x) in place of x in the Maclaurin series expansion for e^x.

Mark

13. ### guitarguy12387 Thread Starter Active Member

Apr 10, 2008
359
12
Hey Ratch,

First of all, thanks for taking the time to help.

I'm not 100% what you're getting at... those are the exact words of the problem. And yes i want to calculate the taylor of f AT x=0 (which is the same thing as the maclaurin of f)

That is how i initially calculated the derivatives for x>0 as well... But as mark44 pointed out, the left and right derivatives at precisely x=0 are not equal, and therefore do not exist.

Mark44,

I am still struggling with how you can write a meaningful expansion at all (even with substitution) if the derivatives at 0 don't exist.

Thanks again for your help, guys. I really appreciate it.

14. ### Ratch New Member

Mar 20, 2007
1,068
4
guitarguy12387,

Whoever wrote or stated the problem was sloppy. Look at the definition of a Taylor series. f(a) +f'(a)*(x-a)+f''(a)*(x-a)^2/2! ... . "a" is the value one is calculating about, and "x" is the value of the function one wants to calculate at. "a" and "x" are not the same thing. If "a" is zero, then it is a Maclaurin series.

That is simple wrong. As you acknowledged, the derivative from the right side of x = 0 is zero. The function is defined to be zero everywhere at x = 0 or x<0. Therefore it is a constant at x = 0 or x<0. That makes the derivative from the left side also zero, which equals the value from the right side. Therefore the nth derivative of the function is zero at x = 0, and does exist. In fact, as I said before, the function is continuous, and all its derivatives exist for all real numbers. Do you remember me stating that fact in my last post?

Ratch

Last edited: Sep 6, 2008
15. ### guitarguy12387 Thread Starter Active Member

Apr 10, 2008
359
12
Ahh i see what you are saying. That makes sense. Thanks.

Ok. I think i see what you're saying. I think i was running into trouble because i was simply trying to plug x=0 back into the derivatives and getting undefined. But since it is the case that f'(t) = exp(-1/x)/x^2 is defined for all x>0, and since the limit as x -> 0 from the right is, in fact 0, the derivative exists and is equal to the derivative at 0 from the left. Does that make sense? I think i understand now... just wanna make sure i am understanding correctly.

Yes, but i wasn't sure why that was the case.

Thanks again for the help.

16. ### Mark44 Well-Known Member

Nov 26, 2007
626
1
Mea culpa. I'm afraid I wasn't much help on this problem. Early on I took a quick look at a graph of the e^(-1/x) part of this function, and noticed that the graph was asymptotic to the line y = 1, but didn't look very closely or even think about the behavior around x = 0. Although I knew f was defined to be 0 for x <= 0, I was mistakenly thinking that for small, positive x, f was quite negative.

Ratch is correct in what he said, that the function is continuous for all reals, and that all of its derivatives exist and are continuous. Ergo, it is possible to get a Taylor series expansion in powers of (x - a), including when a = 0 (the Maclaurin series.

Mark

17. ### Ratch New Member

Mar 20, 2007
1,068
4
Mark44,

Well, sort of. Here is what I mean by that. You can substitute -1/x into the "classic" exp(x) Maclaurin series, and get a series for x<>0. However, "x" will be in the denominator of the series terms instead of the numerator where it usually is. If you want to call that a Maclaurin series, then OK. Exp(-1/x) and its derivatives are undefined at x=0 because the function is discontinuous at x=0. Therefore, I don't see how you can get a Maclaurin series with x in the numerator. Now guitarguy submitted a function that was continuous at x=0, but it was a piece meal stitch together thing that was not defined as exp(-1/x) at x=0. So no valid derivative exists for directly making a Maclaurin series of the function exp(-1/x) with x in the numerator.

Ratch

Last edited: Sep 6, 2008
18. ### Mark44 Well-Known Member

Nov 26, 2007
626
1
No, I wasn't calling the series with x terms in the denominator a Maclaurin series. What I said was that the Taylor series (powers of (x - a)) exists for all values of a, which implies that the Maclaurin series exists.

It doesn't matter that the exp(-1/x) portion of the function wasn't defined at x = 0. What does matter is that the limit, as x --> 0+, of exp(-1/x) exists and is equal to 0, which makes the piecewise function continuous at x = 0. Also, the derivative of the piecewise function exists at x = 0 (the right-side limit is 0, as is the left-side limit). In fact, all of the derivatives of the piecewise function exist at x = 0 and are equal to zero.

Having said all that, here is the Maclaurin series for the piecewise-defined function:

y = 0 + 0*x + 0*x^2 + ... + 0 * x^n + ...

It gives excellent results for all x <= 0, and gives reasonable results for x > 0, as long as x isn't too large.
Mark

19. ### Ratch New Member

Mar 20, 2007
1,068
4
Mark44,

The function exp(-1/x) has no definite value and no derivative at x=0. It can be piecewise defined to be contiguous, but that is not the same as being defined by exp(-1/x) itself. For that reason, I do not believe that a Maclaurin series of numerator terms exist for exp(-1/x).

I do believe that one of the conditions of the Maclaurin or Taylor series is that the function not be a piecewise construction. Unless you specify a range and define a series to cover each range. In the OP's example, y=0 for x=0 or x<0, and y=1-1/1!*x+1/2!*x^2 -1/3!*x^3 ... for x>0

Yeah, it shows that a trivial Maclaurin series for a constant does not hack it when it goes outside its range into an exponential area.

Ratch

20. ### Mark44 Well-Known Member

Nov 26, 2007
626
1
I agree will all this (minor exception -- the usual term is continuous rather than contiguous).

I'm reasonably sure that there is no such condition as you describe (i.e., that a function must not be defined piecewise). IOW, a Maclaurin or Taylor series exists if the function is continuous at x = a, and all of its derivatives exist there. For the function provided by the OP, I have demonstrated that it is continuous at x = 0 and differentiable at x = 0, and have asserted that all of its derivatives exist at x = 0. To boot, I have exhibited the Maclaurin series. If you discover that there is such a condition (that piecewise-defined functions cannot have Taylor series (and hence, Maclaurin series), I trust that you'll let me know.

Mark

BTW, I'm going off into the mountains for several days, so won't be participataing in this forum for the duration.