next up previous contents
Next: About this document ... Up: homework Previous: Taylor polynomials   Contents

The project

Write a function my_cos that approximates by a Taylor polynomial. The subroutine should work for (this is sufficient, since the interval covers one period of the cosine).

The function should take two arguments, and , and should return the value of . The order of the Taylor polynomial is determined inside the function such that


Before returning, the function should print the order of the polynomial determined.

The maximal order allowed for the Taylor polynomial is 100. If we did not succed to properly approximate with polynomials of order up to 100, then probably something is wrong (e.g. the required is smaller than the machine epsilon, etc). In this situation the function prints an error message and returns (the returned value is .

The main program should compute my_cos(x) and cos(x) and compare their values for ; for each tolerance use with .



Adrian Sandu 2001-08-26