CE 335
Computer Assignment 1
An introduction to Matlab programming: A trigonometric function
We will implement a Matlab program to calculate the cosine of a given angle, similar to the builtin
function cos. The numerical method we will use is based on the Taylor series for the cosine function:
1 
x
2
/2! +
x
4
/4! 
x
6
/6! +
x
8
/8!  ...
which converges to cos(x) for all real values of
x
.
(a) Suppose that
x
is between 0 and
π
/2. How many terms in the Taylor series expression would we
need to retain in order to compute cos(
x
) with an absolute truncation error of at most 10
10
? (Invoking
the Alternating Series Test may be useful here  look it up.)
(b) Write a Matlab subroutine that asks for a number and uses your findings from (a) to compute its
cosine. Verify that it works by computing cos(
π
/4) and cos(
π
/3).
(c) How many terms in the Taylor series would you need to retain in order to calculate cos(5) to the
same accuracy using the approach you just implemented?
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '11
 Lybas
 Numerical Analysis, Cos, builtin function

Click to edit the document details