Square root of sum of squares (hypotenuse)
C = hypot(A,B)
Compute the hypotenuse of a right triangle with side lengths of
C = hypot(3,4)
C = 5
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
myhypot = @(a,b)sqrt(abs(a).^2+abs(b).^2);
myhypot does not have the same consideration for underflow and overflow behavior that
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.
ans = 1.4142e+153
ans = Inf
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).
ans = 1.4142e+308
ans = Inf
A,B— Input arraysscalars | vectors | matrices | multidimensional arrays
Input arrays, specified as scalars, vectors, matrices, or multidimensional
be the same size unless one is a scalar. A scalar value expands to
be the same size as the other array.
but one or both inputs is
Complex Number Support: Yes