I want to find the first four Taylor polynomials for f(x) = exp(2*x), centered about x=1. First, I define the function that I'm doing the taylor expansion for. And then I use maple's "taylor" command: > f := exp(2*x); p0 := taylor(f,x=1,1); f := exp(2 x) p0 := exp(2) + O(x - 1) The command "taylor" takes three inputs. The first is the function that you want to consider, exp(x) in this case. The second is the point you want to expand about, x=0 in this case. The third is the degree that you want to go out, plus 1. In this case, I want a 0th degree polynomial, so I made the third input 0+1=1. Okay, so we think we understand what's going on, except that taylor returned the desired function plus this wierd-looking O(x) term. I do this by using the "convert" command below: > p0 := convert(p0,polynom); p0 := exp(2) Now I want to find the Taylor polynomial of degree 1. I do the same as before, but now the third input to the command "taylor" is 1+1=2. Note that I did the taylor and the conversion on the same line. > p1 := taylor(f,x=1,2); p1 := convert(p1,polynom); 2 p1 := exp(2) + 2 exp(2) (x - 1) + O((x - 1) ) p1 := exp(2) + 2 exp(2) (x - 1) Now I want the Taylor polynomial of degree 2. I find both the taylor polynomial and convert the output into a polynomial in one line (I've nested the commands). Note that the change is that the third input to taylor is now 2+1=3. (Also, note that I'm defining p2. I defined p1, and p0 above.) > p2 := convert(taylor(f,x=1,3),polynom); 2 p2 := exp(2) + 2 exp(2) (x - 1) + 2 exp(2) (x - 1) I define the 3rd degree Taylor polynomial now. > p3 := convert(taylor(f,x=1,4),polynom); 2 p3 := exp(2) + 2 exp(2) (x - 1) + 2 exp(2) (x - 1) 3 + 4/3 exp(2) (x - 1) I define the 4th degree Taylor polynomial now. > p4 := convert(taylor(f,x=1,5),polynom); 2 p4 := exp(2) + 2 exp(2) (x - 1) + 2 exp(2) (x - 1) 3 4 + 4/3 exp(2) (x - 1) + 2/3 exp(2) (x - 1) I want to plot both the function and the 0th Taylor polynomial, one in black one in red. Notice that it looks like the exponential function would be in black and the constant in red. So we're happy about how the plot looks like. > plot({f,p0},x=1/3..5/3,color=[black,red]); Now we plot the function and the 1st Taylor polynomial. Again, the colors worked out okay since the first Taylor polynomial came out in red. > plot({f,p1},x=1/3..5/3,color=[black,red]); > plot({f,p2},x=1/3..5/3,color=[black,red]); > plot({f,p3},x=1/3..5/3,color=[black,red]); > plot({f,p4},x=1/3..5/3,color=[black,red]); So from the above, we see that if you're on a fixed interval the taylor polynomial fits better and better the higher the degree. Now, I've found that sometimes maple colors the plots in a way that doesn't make sense. Like in the above example, it'll do the first function in red and the second function in black. I can force maple to do the colors the way _I_ want as follows: > with(plots): > my_plot := [plot(f,x=1/3..5/3,color=black),plot(p1,x=1/3..5/3,color=red)]: > display(my_plot); If you don't have a color printer... > my_plot := [plot(f,x=1/3..5/3,style=line),plot(p1,x=1/3..5/3,style=point)]: > display(my_plot); > fx := diff(f,x); fx := 2 exp(2 x) > plot(fx,x=1/3..5/3); From class, we know that the largest the error |exp(2*x) - P0(x)| can be on [1/3,5/3] is 2^1/1! (2/3)^1 exp(10/3). We see this from above as follows: first I found fx, the derivative of f. Then I plotted fx on the interval in question (1/3,5/3) and looked for where it was largest in absolute value. From the plot, it's at x=5/3. Evaluating fx at 5/3, I get the error bound for f-p0 of 2*(2/3)*exp(10/3). Below, I call E0 that error bound. > Note that I did the evaluating fx at 5/3 using "subs(x=5/3,fx)" > E0 := abs(subs(x=5/3,fx))*(2/3)^1/(1)!; evalf(E0); E0 := 4/3 exp(10/3) 37.37549984 Now I plot the error: exp(2*x) - P0(x). I check that the error bound holds by telling maple to restrict the y-axis to be between -E0 and +E0. Notice that the curve plotted doesn't run through the ceiling or the floor. This is graphical evidence that the error is between -E0 and +E0 for all x in 1/3,5/3 > plot(f-p0,x=1/3..5/3,y=-E0..E0); Note that the error bound fails if you let x be in [-1,3]... see how the plot goes out the ceiling when x gets close to 2? You need a larger value for E0 if you want to control the error on [-1,3]. > plot(f-p0,x=-1..3,y=-E0..E0); Now I want to look at how well p1 approximates f. This means I need to understand fxx on the interval (1/3,5/3) since that's what goes into the error formula. > fxx := diff(fx,x); fxx := 4 exp(2 x) > plot(fxx,x=1/3..5/3); I see that fxx is largest in magnitude at x=5/3. So I will evaluate fxx there and use it in the error bound. From class, we know that the largest the error |exp(2*x) - P1(x)| can be on [1/3,5/3] is 2^2/2! (2/3)^2 exp(10/3): Below, I call E1 that error bound, and I plot the error. Note that the error bound holds! > E1 := abs(subs(x=5/3,fxx))*(2/3)^2/2!; evalf(E1); plot(f-p1,x=1/3..5/3,y=-E1..E1); E1 := 8/9 exp(10/3) 24.91699990 Now, to understand how well p2 approximates f, I need to consider the third derivative of f: > fxxx := diff(fxx,x); fxxx := 8 exp(2 x) > plot(fxxx,x=1/3..5/3); The third derivative is largest in magnitude at x=5/3. So I evaluate there to find the error bound. > E2 := abs(subs(x=5/3,fxxx))*(2/3)^3/3!; evalf(E2); plot(f-p2,x=1/3..5/3,y=-E2..E2); 32 E2 := -- exp(10/3) 81 11.07422218 To understand how well p3 approximates f, I need the fourth derivative of f... > fxxxx := diff(fxxx,x); fxxxx := 16 exp(2 x) > plot(fxxxx,x=1/3..5/3); > E3 := abs(subs(x=5/3,fxxxx))*(2/3)^4/4!; evalf(E3); plot(f-p3,x=1/3..5/3,y=-E3..E3); 32 E3 := --- exp(10/3) 243 3.691407393 To understand how well p4 approximates f, I need the fifth derivative of f.. > fxxxxx := diff(fxxxx,x); fxxxxx := 32 exp(2 x) > plot(fxxxxx,x=1/3..5/3); > E4 := abs(subs(x=5/3,fxxxxx))*(2/3)^5/5!; evalf(E4); plot(f-p4,x=1/3..5/3,y=-E4..E4); 128 E4 := ---- exp(10/3) 3645 .9843753048 > So all the error bounds work fine. In fact, they're very conservative --- we didn't come close to violating them above. Of course, if we looked at larger intervals, they might be violated because they were found for the specific interval [1/3,5/3] and we have no right to demand they work elsewhere...