0
$\begingroup$

I'm terribly green, please forgive me. I need to plot the difference between a chosen calculated Taylor expansion

$e^x=1+x+\frac {x^2}{2!}+\frac {x^3}{3!}+\frac {x^4}{4!}+\frac {x^5}{5!}$...

and the true value of $e^x$ as a function of the number of terms included. I'm excited to work through this but am unsure how to beyond choosing $e^{-3x}≈1-3x+\frac {9x^2}{2}-\frac {9x^3}{2}+\frac {27x^4}{8}-\frac {81x^5}{40}$ and knowing that I need to plot the difference between this and $e^{-3x}$ as a function of 6. I'd like to have a higher number of terms. I'm going to begin by figuring out how to plot functions in general. Any help would be appreciated, particularly with plotting differences of functions.

$\endgroup$
  • 2
    $\begingroup$ I suggest you first try to plot $\exp(\alpha x)$ vs. x; and in the same graph plot the partial sums, $f_0(x)=1$, $f_1(x)=1+\alpha x$ etc. There you will see at what $x$ each partial sum starts deviating from the exponential. $\endgroup$ – Maxim Umansky Jun 12 at 21:48
0
$\begingroup$

So why don't you very literally do what is being asked. The difference between two curves is the surface area between the two curves. This is 1 number, which you can then plot as a function of the number of terms in the Taylor expansion. There is however a small snag, the area will depend on the range of x's you consider. So there are two options, either you use this as a second parameter (so you get a 3D plot: X= the x-range, Y= the number of terms in the Taylor expansion, Z, the difference value you calculate.) or just keep it fixed. For the latter it may be of interest to check 2 things:

  1. Is the relative value of the difference (i.e. the calculated area divided by the area under the exp(x) curve) constant for increasing ranges?
  2. Or does it converge towards a specific value? These two, if either is true, will held you reduce the 3D plot again to a 2D plot, where the x-range parameter can be dropped again.

The actual plotting can be done with any graphics software that can read the output from your program (read it in excell an plot, 2D only), use xmgrace or gnuplot (2D and 3D).

Don't try to overthink problems like this, always remember KISS=Keep It Simple & Stupid.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.