Use the Taylor series given in Key Idea 32 to create the Taylor series of the given functions.

29. \(f(x) = e^xsin(x)\) (only find the first 4 terms)

Key Idea 32 informs us that \(e^x=1+x+\frac{x^2}{2!}+\frac{x^3}{3!}+...\) and \(sinx=x-\frac{x^3}{3!}+\frac{x^5}{5!}-\frac{x^7}{7!}+...\)

so that \(e^xsin(x)=(1+x+\frac{x^2}{2!}+\frac{x^3}{3!}+...)(x-\frac{x^3}{3!}+\frac{x^5}{5!}-\frac{x^7}{7!}+...)\).

To find the series, we can go two ways about this: either distribute the expressions and collect the first four terms or evaluate all the necessary derivates of \(e^xsinx\) and compute the Taylor series directly.

For distributing the expressions:

\(f(x)=1(x-\frac{x^3}{3!}+\frac{x^5}{5!}-\frac{x^7}{7!}+...)+x(x-\frac{x^3}{3!}+\frac{x^5}{5!}-\frac{x^7}{7!}+...)+\frac{x^2}{2!}(x-\frac{x^3}{3!}+\frac{x^5}{5!}-\frac{x^7}{7!}+...)+...\) which will eventually add up to \(f(x)=0+x+x^2+\frac{x^3}{3}+...\)

For evaluating derivatives:

Use the Maclaurin series (Taylor series for f(c) when c=0): \(\sum_{n=0}^{\infty}\frac{f^n(0)}{n!}x^n=f(0)+\frac{f'(0)}{1!}x+\frac{f''(0)}{2!}x^2+\frac{f'''(0)}{3!}x^3+...+\frac{f^n(0)}{n!}x^n\)

Now, we find the terms:

\(f(0) = e^0sin(0)=0\)

\(f'(x)=(e^x)(\frac{d}{dx}sinx)+(\frac{d}{dx}e^x)(sinx)=e^xcosx+e^xsinx\) \(f'(0)=e^0cos0+e^0sin0=1\)

\(f''(x)=(\frac{d}{dx}e^xcosx)+(\frac{d}{dx}e^xsinx)=-e^xsinx+e^xcosx+e^xcosx+e^xsinx= 2e^xcosx\) \(f''(0)=2e^0cos0=2\)

\(f'''(x)=\frac{d}{dx}2e^xcosx=2\Big((e^x)(\frac{d}{dx}cosx)+(\frac{d}{dx}e^x)(cosx)\Big)=2(-e^xsinx+e^xcosx)=2e^xcosx-2e^xsinx\) \(f'''(0)=2e^0cos0-2e^0sin0=2\)

Substitute terms into Maclaurin series:

\(f(x)=f(0)+\frac{f'(0)}{1!}x+\frac{f''(0)}{2!}x^2+\frac{f'''(0)}{3!}x^3+...=0+\frac{1}{1}x+\frac{2}{2}x^2+\frac{2}{6}x^3=0+x+x^2+\frac{x^3}3+...\)

And you can see in the plot below that for every derivative evaluated (every new term added onto the series) estimating the function becomes more and more accurate.

equation1 = function(x){exp(x)*sin(x)}
equation2 = function(x){0*x}
equation3 = function(x){x}
equation4 = function(x){x+x^2}
equation5 = function(x){x+x^2+((x^3)/(3))}
curve(equation1, col="blue",lwd=5, ylab = "y", main = "Maclaurin Series for e^x(sinx)")
curve(equation2, col="red",lwd=3, add=TRUE)
curve(equation3, col="purple",lwd=3, add=TRUE)
curve(equation4, col="green",lwd=2, add=TRUE)
curve(equation5,lwd=3, add=TRUE)

legend( "topleft", inset = c(0,0), cex = 1,
        bty = "n", legend = c("e^x(sinx)", "0","x","x+x^2","x+x^2+(x^3/3)"), 
        text.col = c("blue","red", "purple","green","black"), 
        col = c("blue","red", "purple","green","black"), 
        pt.bg = c("blue","red", "purple","green","black"), 
        pch = c(0,0))