# Taylor Series of piecewise functions

#### guitarguy12387

Joined Apr 10, 2008
359
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.

#### Mark44

Joined Nov 26, 2007
628
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.

#### silvrstring

Joined Mar 27, 2008
159
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.

#### Mark44

Joined Nov 26, 2007
628
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.
That works for me. As your work shows, there's more than one way to get a series expansion for a particular function.

#### silvrstring

Joined Mar 27, 2008
159
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?

#### Mark44

Joined Nov 26, 2007
628
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.

#### silvrstring

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

#### guitarguy12387

Joined Apr 10, 2008
359
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.

#### silvrstring

Joined Mar 27, 2008
159
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:

#### guitarguy12387

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

all of the derivatives of f(x) for x=0 will be 0, and y approaches infinity as x-->0 from the left.
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).

#### Ratch

Joined Mar 20, 2007
1,070
guitarguy12387,

12387? How many of you guitarguys are there?

Why is the result interesting?
I don't know, do you?

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

The part that i am struggling is with is how to approach the problem being that it is a piecewise function.
We will take it one piece at a time.

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 0.
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.

Right that makes sense. But, as you said,

Quote:
all of the derivatives of f(x) for x=0 will be 0, and y approaches infinity as x-->0 from the left.

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).
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 hope someone will be able to point me in the right direction.
I'm trying.

Ratch

#### Mark44

Joined Nov 26, 2007
628
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.
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

#### guitarguy12387

Joined Apr 10, 2008
359
Hey Ratch,

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

Quote:
Calculate the Taylor series at x=0
You mean about x=0, not at x=0. In other words, you want to calculate the Maclaurin series.
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)

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?
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.

#### Ratch

Joined Mar 20, 2007
1,070
guitarguy12387,

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)
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 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.
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:

#### guitarguy12387

Joined Apr 10, 2008
359
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.
Ahh i see what you are saying. That makes sense. Thanks.

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.
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.

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?
Yes, but i wasn't sure why that was the case.

Thanks again for the help.

#### Mark44

Joined Nov 26, 2007
628
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

#### Ratch

Joined Mar 20, 2007
1,070
Mark44,

Ergo, it is possible to get a Taylor series expansion in powers of (x - a), including when a = 0 (the Maclaurin series.
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:

#### Mark44

Joined Nov 26, 2007
628
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.
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

#### Ratch

Joined Mar 20, 2007
1,070
Mark44,

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.
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).

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.
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

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.
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

#### Mark44

Joined Nov 26, 2007
628
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 agree will all this (minor exception -- the usual term is continuous rather than contiguous).

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
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.