%% Overflow and Underflow Behavior
% Examine the difference between using hypot and coding the basic hypot equation in M-code.
% Create an anonymous function that performs essentially the same basic function as hypot.

myhypot = @(a,b)sqrt(abs(a).^2+abs(b).^2);

% myhypot does not have the same consideration for underflow and overflow behavior that hypot offers.
%
% Find the upper limit at which myhypot returns a useful value. You can see that this test function reaches its maximum at about 1e154, returning an infinite result at that point.

myhypot(1e153,1e153)

%

myhypot(1e154,1e154)

%
% Do the same using the hypot function, and observe that hypot operates on values up to about 1e308, which is approximately equal to the value for realmax on your computer (the largest representable double-precision floating-point number).

hypot(1e308,1e308)

%

hypot(1e309,1e309)

% Copyright 2012 The MathWorks, Inc.