Problem 1.6.2

Script: Prob1_6_2.m for Math 426/Cisc 410 R.J. Braun

Contents

format compact;  % get rid of white space

Part (a)

The condition number is f''(x) = 1/sqrt(x^2-1). The conditioning appears to be fine as abs(x) increases.

Part (b)

format long;
t = -4:-4:-16;
x = cosh(t);
tt = log(x-sqrt(x.^2 - 1));
errorb = abs(t-tt);
%
disp(' g(x) = log(x-sqrt(x.^2-1)) ')
disp(' t          x                g(x)           error  ')
disp('----------------------------------------------------')
for k = 1:4
      disp(sprintf('%3.0f    %7.4e    %16.12g  %8.5e',t(k),x(k),tt(k),errorb(k)))
end
 g(x) = log(x-sqrt(x.^2-1)) 
 t          x                g(x)           error  
----------------------------------------------------
 -4    2.7308e+001                  -4  4.61853e-014
 -8    1.4905e+003      -8.00000000017  1.71090e-010
-12    8.1377e+004      -12.0000001371  1.37072e-007
-16    4.4431e+006      -15.9986248712  1.37513e-003

Part (c)

ttt = -2*log( sqrt((x+1)/2) + sqrt((x-1)/2) );
errorc = abs(t-ttt);
disp(' ')
disp(' h(x) = -2 log( sqrt((x+1)/2) + sqrt((x-1)/2) ) ')
disp(' t          x                h(x)           error  ')
disp('----------------------------------------------------')
for k = 1:4
      disp(sprintf('%3.0f    %7.4e    %16.12g  %8.5e',t(k),x(k),ttt(k),errorc(k)))
end
 
 h(x) = -2 log( sqrt((x+1)/2) + sqrt((x-1)/2) ) 
 t          x                h(x)           error  
----------------------------------------------------
 -4    2.7308e+001                  -4  0.00000e+000
 -8    1.4905e+003                  -8  0.00000e+000
-12    8.1377e+004                 -12  0.00000e+000
-16    4.4431e+006                 -16  0.00000e+000

Part (d)

The formula of part (b) is unstable; the formula of part (d) is stable. The argument of the log contains a difference of two closely spaced numbers causing subtractive cancelation! Part (c) avoids this.