Docsity

Maple Lab for Calculus II: Floating-Point Computations and Numerical Integration - Prof. D, Lab Reports of Mathematics

Toggle sidebar
bg1
Maple Lab for Calculus II Lab M
Introduction to Floating-Point Computations
Douglas B. Meade
Department of Mathematics
Overview
Calculations with floating-point numbers must be done with care. Computations done with-
out some forethought and planning can easily lead to incorrect or nonsensical conclusions.
For example, based solely on numerical evidence, one might conclude the harmonic series
converges. The purposes of this lab, and project, are to alert you to some of the potential
problems and ways they can be addressed.
Preparation
The Activities and Project 3 involve various topics from earlier in the course:
•(conditional) convergence of the alternating harmonic series
•approximation of definite integrals using left, right, midpoint, trapezoid, and Simpson
approximations.
Review these topics for this lab (and as early preparation for the final exam).
Maple Essentials
•New Maple commands introduced in this lab include:
Command Description
ApproximateInt visual, numeric, or symbolic representation of a Riemann
sum;
in the Student[Calculus1] package
>ApproximateInt( f,a..b, partition=N,
>method=left, output=plot );
(see also Lab 13 for Calculus I, Fall 2004)
Digits maximum number of significant (decimal) digits in a
floating-point number
>Digits := 5;
(the default value is 10)
print print one or more Maple quantities
>print( 9, 9^9, 9! );
printf formatted printing of one or more Maple quantities
>printf( "%5a %10a %10a\n", 9, 9^9, 9! );
(see ?printf for full formatting details)
[for ...] [from ...]command for controlling iterative loops
[to ... ] [by ...]the for,from,to, and by clauses are all optional
[while ...]only the do and end do are required;
do ... end do explicit examples are provided in the Activities
Assignment
•Project 3 is due at the beginning of next week’s lab.
•Mastery Quiz 10 will be distributed at the end of today’s lab.
•In next week’s lab you will have time to complete Mastery Quiz 11.
Version 3.1 (Spring 2005) Created 11 April 2005
pf3

Partial preview of the text

Download Maple Lab for Calculus II: Floating-Point Computations and Numerical Integration - Prof. D and more Lab Reports Mathematics in PDF only on Docsity!

Introduction to Floating-Point Computations

Douglas B. Meade

Department of Mathematics

Overview

Calculations with floating-point numbers must be done with care. Computations done with- out some forethought and planning can easily lead to incorrect or nonsensical conclusions. For example, based solely on numerical evidence, one might conclude the harmonic series converges. The purposes of this lab, and project, are to alert you to some of the potential problems and ways they can be addressed.

Preparation

The Activities and Project 3 involve various topics from earlier in the course:

  • (conditional) convergence of the alternating harmonic series
  • approximation of definite integrals using left, right, midpoint, trapezoid, and Simpson approximations.

Review these topics for this lab (and as early preparation for the final exam).

Maple Essentials

  • New Maple commands introduced in this lab include: Command Description ApproximateInt visual, numeric, or symbolic representation of a Riemann sum; in the Student[Calculus1] package

ApproximateInt( f , a..b, partition=N , method=left, output=plot ); (see also Lab 13 for Calculus I, Fall 2004) Digits maximum number of significant (decimal) digits in a floating-point number Digits := 5; (the default value is 10) print print one or more Maple quantities print( 9, 9^9, 9! ); printf formatted printing of one or more Maple quantities printf( "%5a %10a %10a\n", 9, 9^9, 9! ); (see ?printf for full formatting details) [for ...] [from ...] command for controlling iterative loops [to ... ] [by ...] the for, from, to, and by clauses are all optional [while ...] only the do and end do are required; do ... end do explicit examples are provided in the Activities

Assignment

  • Project 3 is due at the beginning of next week’s lab.
  • Mastery Quiz 10 will be distributed at the end of today’s lab.
  • In next week’s lab you will have time to complete Mastery Quiz 11.

Activities

  1. The following segment of Maple code uses a loop to find and display the first few Maclau- ring coefficients of f (x) = arctan(x):

    f := arctan(x); # define function a := 1; # define base point for Taylor expansion for k from 1 to 15 do df := diff( f, x$k ); # compute kth derivative dfa := eval( df, x=a ); # evaluated at x = 0 printf( " %3a %20a\n", k, dfa/k! ); # display coefficient of (x − a)k^ in Taylor polynomial end do: # note use of colon here

  2. Modify the code in Activity 1 to assemble the 20th Maclaurin polynomial for erf(x) = 2 √ π

∫ (^) x

0

e−t

2 dt.

  1. “Machine epsilon” is defined to be the largest positive number  such that (numerically) 1 +  = 1. (In the real numbers,  = 0, but not for floating-point numbers.) Consider the following Maple loop:

    Digits := 6; # maximum number of decimal digits for k from 0 to 12 do q := 1+10^(-k); # compute 1 +  (†) printf( " %3a %15a %30 %15a \n", k, 10^k, q, evalf(q) ); end do; An estimate of machine epsilon can be obtained from this table of values. How does machine epsilon change with the value of Digits? Note: Maple has no trouble working with arbitrarily large integers; this effect is a concern only for floating-point arithmetic.

  2. Repeat Activity 3 with the command marked as (†) changed to q := 1+10^k;.
  3. It is important to be aware of machine epsilon when trying to compute the value of an infinite series,

∑∞ k=1 ak.^ If the terms of the series converge to zero (as we know they must for any convergent series), then — eventually — the ak <  and adding additional terms contributes nothing to the computed sum. That is, the series appears to converge!

a := k -> 1/k; # define terms in harmonic series Digits := 6; # maximum number of decimal digits SUM := 0.0; # initialize sum to zero for k from 1 to 100000 do # add next term to sum (‡) SUM := SUM + a(k); end do: # with a ;, output is 100,000 lines! SUM; # final sum Change the value of Digits (and possibly the upper bound on the sum) and observe how the “sum” of the harmonic series changes.

  1. Repeat Activity 5 for the alternating harmonic series. Explain why the sum of this series is not as sensitive to the value of Digits. Hint: Recall that the alternating harmonic series is conditionally convergent.