%% Problem 1.6.2 % Script: Prob1_6_2.m for Math 426/Cisc 410 % R.J. Braun %% 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 %% 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 %% 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.