Andrew Aggarwala 9/16/99

HW #1

 

1) Involves running and explaining the previously written program epsi.f. The output is given below.

 

0.500000 0.707107

0.250000 0.500000

0.125000 0.353553

6.25000E-02 0.250000

3.12500E-02 0.176777

1.56250E-02 0.125000

7.81250E-03 8.83883E-02

3.90625E-03 6.25000E-02

1.95312E-03 4.41942E-02

9.76562E-04 3.12500E-02

4.88281E-04 2.20971E-02

2.44141E-04 1.56250E-02

1.22070E-04 1.10485E-02

6.10352E-05 7.81250E-03

3.05176E-05 5.52427E-03

1.52588E-05 3.90625E-03

7.62939E-06 2.76214E-03

3.81470E-06 1.95312E-03

1.90735E-06 1.38107E-03

9.53674E-07 9.76562E-04

4.76837E-07 6.90534E-04

2.38419E-07 4.88281E-04

1.19209E-07 3.45267E-04

5.96046E-08 2.44141E-04

 

The purpose of epsi.f is to determine the "machine epsilon" (eps), which is defined as the smallest floating point number such that (1 + eps > 1). After being initialized with a value of 1.0, eps is used in a recursive loop where it's value is halved each iteration. The loop will end only when (eps + 1) is greater then 1. The fact that the loop ever ends proves that round off error occurs within the computer, and that the value of

(1+epsmax) where epsmax <= 1.00E-08 is equal to 1 in the computers calculations.

 

 

 

 

 

 

 

 

 

 

 

2) Work out the Taylor Polynomial for cos(x) using Maple and explain.

 

> fun:=cos(x); [define cos(x)]

fun := cos(x)

 

> tylrs:=taylor(fun,x=a); [using the taylor function, develop the taylor series expansion of cos(x) in the general form]

 

tylrs := cos(a) - sin(a) (x - a) - 1/2 cos(a) (x - a)^2 + 1/6 sin(a) (x - a)^3

 

+ 1/24 cos(a) (x - a)^4 - 1/120 sin(a) (x - a) ^5 + O((x - a) ^6)

 

> tylrp:=convert(tylrs,polynom); [converts the taylor series expansion into a taylor polynomial by dropping the Remainder term]

 

tylrp := cos(a) - sin(a) (x - a) - 1/2 cos(a) (x - a) ^2 + 1/6 sin(a) (x - a)^3

 

+ 1/24 cos(a) (x - a)^4 - 1/120 sin(a) (x - a)^5

 

> tylrs3:=taylor(fun,x=0,4);tylrs9:=taylor(fun,x=0,10); [form the taylor series of thrid and ninth order respectively]

 

tylrs3 := 1 - 1/2 x^2 + O(x^4 )

 

tylrs9 := 1 - 1/2 x^2 + 1/24 x^4 - 1/720 x^6 + 1/40320 x^8 + O(x^10 )

 

> tylrp3:=convert(tylrs3,polynom);tylrp9:=convert(tylrs9,polynom); [convert the above taylor series into Taylor Polynomials]

 

tylrp3 := 1 - 1/2 x^2

 

tylrp9 := 1 - 1/2 x^2 + 1/24 x^4 - 1/720 x^6 + 1/40320 x^8

 

> y0:=evalf(subs(x=0.1,fun));y3:=evalf(s\

> ubs(x=0.1,tylrp3));y9:=evalf(subs(x=0.1,tylrp9)); [Evaluate the actual function cos(x), the 3rd and 9th order Taylor Polynomials at x=0.1]

 

y0 := .9950041653

 

y3 := .9950000000

 

y9 := .9950041653

 

 

 

> error3:=abs(y3-y0);error9:=abs(y9-y0); [Computes the error term between the 3rd order approximation with the actual function, and the 9th order approx. with the actual function. As expected the higher order approximation gives the exact solutionàexact to the machine epsilon of 1.00E-08]

error3 := .41653 10E-5

 

error9 := 0

 

 

 

 


Updated: 1999-09-16, 12:25