Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

我们为许可用户提供了部分翻译好的中文文档。您只需登录便可查阅这些文档

hypot

Square root of sum of squares (hypotenuse)

Syntax

C = hypot(A,B)

Description

example

C = hypot(A,B) returns the result of the following equation, computed to avoid underflow and overflow:

C = sqrt(abs(A).^2 + abs(B).^2)

Examples

collapse all

Compute the hypotenuse of a right triangle with side lengths of 3 and 4.

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 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)
ans = 1.4142e+153
myhypot(1e154,1e154)
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).

hypot(1e308,1e308)
ans = 1.4142e+308
hypot(1e309,1e309)
ans = Inf

Input Arguments

collapse all

Input arrays, specified as scalars, vectors, matrices, or multidimensional arrays. Inputs A and B must either be the same size or have sizes that are compatible (for example, A is an M-by-N matrix and B is a scalar or 1-by-N row vector). For more information, see Compatible Array Sizes for Basic Operations.

If neither A nor B is Inf, but one or both inputs is NaN, then hypot returns NaN.

Data Types: single | double
Complex Number Support: Yes

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

See Also

| |

Introduced before R2006a


Was this topic helpful?