COMP 2031 Computer Science Foundations
Assignment 1, to be submitted online. See website or course outline for due date.
Power series approximations and differences for the exponential function
Your submission for this assignment should be a report consisting of sentences and paragraphs that in- troduce and explain the subject matter and answer the questions raised. Marks will be awarded for the quality of your exposition. Your report should be typed and submitted as a pdf or Word document or similar. Your program(s) for the tasks given below should be included as appendices to the report.
Euler’s number e is transcendental (certainly not rational). A scientific calculator might be able to tell
you that e = 2.718281828459045235 (18 decimal places). In calculus, e and the exponential function ex
have special properties, including the fact that the area beneath the graph of 1 between x = 1 and x = e
x
n=0
[Recall that for n > 0, n! is the product of all the positive integers up to and including n, that is,
n! = 1 · 2 · 3 · · · n, and that 0! = 1.]
In practise we will need to truncate the infinite power series to a polynomial approximation. Consider the degree seven partial sum:
equals 1.
One way to calculate values of ex is to use the infinite power series: x∞xn1xx2 x3
e =
n! =1+1+1·2+1·2·3+···
S7(x)=
7 xn x2 x3 x4 x5 x6 x7
n! =1+x+ 2 + 6 +24+120+720+5040.
n=0
In a programming language of your own choice, write a program that is capable of evaluating S7(x) for
any real number x. In the 19th century, values of S7(x) would have been tabulated using differences. Use your code to evaluate S7(x) for eleven values of x, regularly spaced at intervals of 0.1 between 0 and 1 inclusive. That is, calculate S7(0.0), S7(0.1), S7(0.2), . . . , S7(1.0). Use the standard level of accuracy
for floating point numbers for these evaluations; whatever that is in the language that you are using. List the values in a table and also calculate first differences, second differences and so on all the way to eighth differences.
x
S7 (x)
1st diff 2nd diff 3rd diff 4th diff 5th diff 6th diff 7th diff 8th diff
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
1
Since the polynomial S7 is of degree seven, the seventh differences should all be the same and the eighth differences should be zero. Do your seventh differences (you should have four of them) all look the same? Are your eighth diffferences all identically zero? If not, can you explain why they are not?
Is there a more precise type of floating point number available? Use it to re-calculate all the values and differences. There is no need to display all these numbers in a table, but do report and comment on the values of the seventh and eighth differences and how they differ from those previously calculated with less precision.
Now compare the correct value of e (which is e1) with the approximations you have calculated above by evaluating S7(1) in normal precision and with extra precision. How well do your approximations agree with the value given above (to 18 decimal places)?
Use a program to evaluate and tabulate both Sn(1) and e − Sn(1) for n = 7, 8, 9, . . . , 16. Does the value of e − Sn(1) decrease as n increases?
Another way to calculate the value of e is to use the property that 1n
e=lim1+ . n→∞ n
Again, we can’t practically let n go to infinity, but we can use some large values of n. Calculate this expression and tabulate values of 1 + 1 n for n being various powers of 10. Say n = 100, n = 1000, . . . ,
n
n = 1000 000 000 000 = 1012. The approximations should get more accurate as n gets larger, but do they? Is your accuracy limited by the precision with which 1 + 1 is being stored? Try ordinary precision and
n
‘extra’ precision.
There is a wealth of information about e (Euler’s number) and its properties and approximations in books and on the internet. If you use any such information then your report for this assignment must have a
bibliography and contain appropriate references. Include your computer program(s) as appendices. Your report should explain what you have done and what you discovered, using sentences and paragraphs. The 1000 words in the Course Outline is a guide only and excludes your references and program(s).
Report Your report on this assignment should clearly answer all the questions. It is recommended that you use tables to present the various approximations that you find. This will make it easy for the reader to find them. Also use sentences of explanation to put those approximations and other results in context. Remember that you do not need more than 1000 words, excluding the bibliography and appendix.
END