Docsity

Esercizi di Algebra Lineare e Geometria - Computing Scientifico - Prof. Carlini, Esercizi di Algebra Lineare e Geometria Analitica

Toggle sidebar
bg1
Linear Algebra and Geometry - Scientific Computing
Exercise session 1
Topics: finite arithmetic, cancellation error
1. Consider a computer which uses floating-point arithmetic with base N= 10, t= 5 digits for mantissa
and rounding rule. Introduce the following numbers:
a= 1.483593 ,
b= 1.484111.
Determinate the result of ¯s= ¯a¯
b, where ¯xstands for machine-number corresponding to xin the
used floating-point arithmetic and stands for the machine-subtraction. Compare ¯swith c=a−b
and then compute the relative error of ¯s.
2. Evaluate the functions:
f1(x) = 1−cos(x)
x2, f2(x) = ex−1
x,
f3(x)=1−p1−x2, f4(x) = (x+ 1)2−1
x
in x= 10−n,n= 1,2, .., 16. After that, reformulate the functions in order to avoid cancellation error.
Assuming the values obtained using reformulated functions as exact values, compute relative errors
and compare them with machine precision. Print the relative error for every value of xand graphically
represent it.
3. Consider the sequence
x1= 2
xn= 2n−1/2r1−q1−41−nx2
n−1, n ≥2
which gives a πapproximation. Compute the relative errors |π−xn|/π for n= 1, ..., 40 and plot the
relative errors behavior using logarithmic scale. After that, determine an expression ˜xnequivalent to
xnwhich avoids cancellation error. Graphically represent relative errors |π−˜xn|/π for n= 1, ..., 40
using logarithmic scale. Compare this plot with the previous one and comment the results.
4. Given the function f(x) = sin(x), approximate f0(x) using the following difference quotient
f0(x)≈r(x) = sin(x+h)−sin(x)
h,
with h= 2−k,k= 1,2, ..., 50.
Fix for instance x=π/4; graphically represent the relative error |f0(x)−r(x)|/|f0(x)|and comment
the results. After that, reformulate r(x) in order to avoid cancellation errors and graphically represent
the relative error.
1

Anteprima parziale del testo

Scarica Esercizi di Algebra Lineare e Geometria - Computing Scientifico - Prof. Carlini e più Esercizi in PDF di Algebra Lineare e Geometria Analitica solo su Docsity!

Linear Algebra and Geometry - Scientific Computing

Exercise session 1

Topics: finite arithmetic, cancellation error

  1. Consider a computer which uses floating-point arithmetic with base N = 10, t = 5 digits for mantissa and rounding rule. Introduce the following numbers:

a = 1. 483593 , b = 1. 484111.

Determinate the result of ¯s = ¯a ¯b, where ¯x stands for machine-number corresponding to x in the used floating-point arithmetic and stands for the machine-subtraction. Compare ¯s with c = a − b and then compute the relative error of ¯s.

  1. Evaluate the functions:

f 1 (x) =

1 − cos(x) x^2 , f 2 (x) =

ex^ − 1 x

f 3 (x) = 1 −

1 − x^2 , f 4 (x) = (x + 1)^2 − 1 x

in x = 10−n, n = 1, 2 , .., 16. After that, reformulate the functions in order to avoid cancellation error. Assuming the values obtained using reformulated functions as exact values, compute relative errors and compare them with machine precision. Print the relative error for every value of x and graphically represent it.

  1. Consider the sequence

x 1 = 2

xn = 2n−^1 /^2

1 − 41 −nx^2 n− 1 , n ≥ 2

which gives a π approximation. Compute the relative errors |π − xn|/π for n = 1, ..., 40 and plot the relative errors behavior using logarithmic scale. After that, determine an expression ˜xn equivalent to xn which avoids cancellation error. Graphically represent relative errors |π − x˜n|/π for n = 1, ..., 40 using logarithmic scale. Compare this plot with the previous one and comment the results.

  1. Given the function f (x) = sin(x), approximate f ′(x) using the following difference quotient

f ′(x) ≈ r(x) =

sin(x + h) − sin(x) h

with h = 2−k, k = 1, 2 , ..., 50. Fix for instance x = π/4; graphically represent the relative error |f ′(x) − r(x)|/|f ′(x)| and comment the results. After that, reformulate r(x) in order to avoid cancellation errors and graphically represent the relative error.