Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
hypot( ) function?

Subject: hypot( ) function?

From: Jack Crenshaw

Date: 2 Apr, 2010 16:31:19

Message: 1 of 10

Anyone know anything about this function? I'm using an old version of
Matlab (6), and it's used in a couple of my Simulink library blocks.

Funny thing is, it's not shown as an m-file. The line "help hypot" turns
up no match. Yet, it's there. If I type hypot([3,4]) I get 5.

I think this must be the first time I've encountered an undocumented
function in Matlab. That makes me curious about it. And it makes me
wonder: what other neat little functions are hidden away in there?

Jack

Subject: hypot( ) function?

From: Wayne King

Date: 2 Apr, 2010 16:45:16

Message: 2 of 10

Jack Crenshaw <jcrens@earthlink.net> wrote in message <gKGdnfpX1PxFhivWnZ2dnUVZ_qednZ2d@earthlink.com>...
> Anyone know anything about this function? I'm using an old version of
> Matlab (6), and it's used in a couple of my Simulink library blocks.
>
> Funny thing is, it's not shown as an m-file. The line "help hypot" turns
> up no match. Yet, it's there. If I type hypot([3,4]) I get 5.
>
> I think this must be the first time I've encountered an undocumented
> function in Matlab. That makes me curious about it. And it makes me
> wonder: what other neat little functions are hidden away in there?
>
> Jack

Hi Jack, In more current versions of MATLAB, hypot() is documented with both command line help and documentation. It is a built-in function.

Wayne

Subject: hypot( ) function?

From: James Tursa

Date: 2 Apr, 2010 20:16:20

Message: 3 of 10

Jack Crenshaw <jcrens@earthlink.net> wrote in message <gKGdnfpX1PxFhivWnZ2dnUVZ_qednZ2d@earthlink.com>...
> Anyone know anything about this function? I'm using an old version of
> Matlab (6), and it's used in a couple of my Simulink library blocks.
>
> Funny thing is, it's not shown as an m-file. The line "help hypot" turns
> up no match. Yet, it's there. If I type hypot([3,4]) I get 5.
>
> I think this must be the first time I've encountered an undocumented
> function in Matlab. That makes me curious about it. And it makes me
> wonder: what other neat little functions are hidden away in there?
>
> Jack

For hypot, you can see the source code that TMW apparently used as the algorithm for their built-in function here:

http://www.netlib.org/fdlibm/e_hypot.c

James Tursa

Subject: hypot( ) function?

From: Jack Crenshaw

Date: 3 Apr, 2010 06:47:39

Message: 4 of 10

Ok, guys, thanks.

Wow, that's a really busy sqrt(sum-of-squares), isn't it? I'm impressed.

Jack

James Tursa wrote:
> Jack Crenshaw <jcrens@earthlink.net> wrote in message
> <gKGdnfpX1PxFhivWnZ2dnUVZ_qednZ2d@earthlink.com>...
>> Anyone know anything about this function? I'm using an old version of
>> Matlab (6), and it's used in a couple of my Simulink library blocks.
>>
>> Funny thing is, it's not shown as an m-file. The line "help hypot"
>> turns up no match. Yet, it's there. If I type hypot([3,4]) I get 5.
>>
>> I think this must be the first time I've encountered an undocumented
>> function in Matlab. That makes me curious about it. And it makes me
>> wonder: what other neat little functions are hidden away in there?
>>
>> Jack
>
> For hypot, you can see the source code that TMW apparently used as the
> algorithm for their built-in function here:
>
> http://www.netlib.org/fdlibm/e_hypot.c
>
> James Tursa

Subject: hypot( ) function?

From: Steven Lord

Date: 5 Apr, 2010 03:52:26

Message: 5 of 10


"Jack Crenshaw" <jcrens@earthlink.net> wrote in message
news:UMmdnZVJ0bgWeSvWnZ2dnUVZ_qqdnZ2d@earthlink.com...
> Ok, guys, thanks.
>
> Wow, that's a really busy sqrt(sum-of-squares), isn't it? I'm impressed.

Well, the naive implementation (square x, square y, add them, take the
square root) could run into overflow or underflow problems, as described on
the Wikipedia page:

http://en.wikipedia.org/wiki/Hypot

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: hypot( ) function?

From: Derek O'Connor

Date: 7 Apr, 2010 18:27:24

Message: 6 of 10

"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <hp5jak$c3e$1@fred.mathworks.com>...
> Jack Crenshaw <jcrens@earthlink.net> wrote in message <gKGdnfpX1PxFhivWnZ2dnUVZ_qednZ2d@earthlink.com>...
- snip -
>
> For hypot, you can see the source code that TMW apparently used as the algorithm for their built-in function here:
>
> http://www.netlib.org/fdlibm/e_hypot.c
>
> James Tursa

------------------------------------

I remember reading a very nice paper on this problem nearly 30 years ago:

> Cleve Moler and Donald Morrison,
> ``Replacing Square Roots by Pythagorean Sums,''
> IBM Journal of Research and Development,
> Vol. 27, Number 6,
> pp. 577-581,
> Nov. 1983

Their algorithm has 3rd Order convergence and avoids overflow.

Unfortunately, IBM has just changed their policy and the public can no longer access their journals online. Maybe Cleve Moler could put it on his website, or better still, do a complete new essay on the problem. It would fit nicely into his Matlab book.

Here is an interesting discussion (C programs, alas for me):
http://steve.hollasch.net/cgindex/math/pythag-root.txt

Derek O'Connor

Subject: hypot( ) function?

From: James Tursa

Date: 7 Apr, 2010 18:42:25

Message: 7 of 10

"Derek O'Connor" <derekroconnor@eircom.net> wrote in message <hpiiqc$8qe$1@fred.mathworks.com>...
>
> Unfortunately, IBM has just changed their policy and the public can no longer access their journals online.

This seems to be an increasing problem in general. In this digital age, I am coming to believe that it is necessary to copy as much of this kind of stuff to personal storage somewhere so that I can retain access to it. What was once easy to get at online suddenly disappears.

James Tursa

btw ... thanks for the link ... I am currently copying it to my HD.

Subject: hypot( ) function?

From: Derek O'Connor

Date: 7 Apr, 2010 23:56:05

Message: 8 of 10

"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <hpijmh$lv6$1@fred.mathworks.com>...
> "Derek O'Connor" <derekroconnor@eircom.net> wrote in message <hpiiqc$8qe$1@fred.mathworks.com>...
> >
> > Unfortunately, IBM has just changed their policy and the public can no longer access their journals online.
>
> This seems to be an increasing problem in general. In this digital age, I am coming to believe that it is necessary to copy as much of this kind of stuff to personal storage somewhere so that I can retain access to it. What was once easy to get at online suddenly disappears.
>
> James Tursa
>
> btw ... thanks for the link ... I am currently copying it to my HD.
------------------------------------------------------------

I'm still searching on my HDs and web for Moler & Morrison' paper, but no luck so far.

I wrote and tested this PythagSum algorithm in Fortran and Pascal many years ago but couldn't find them (on 5 1/4 inch floppies somewhere) so I translated the C version found on Steve Hollasch's site (above) into Matlab.

I'm amazed how well it works: 1 to 3 iterations of the loop and it handles inputs x and y from 4.92e-324 to 1.27e+308 without under or overflow.

sqrt(x^2 + y^2) is limited to 2.22e-162 to 6.70e+153.

The function and tests are here:
http://www.scribd.com/doc/29567048/TestPythagSum


Derek O'Connor.

Subject: hypot( ) function?

From: Derek O'Connor

Date: 8 Apr, 2010 00:45:20

Message: 9 of 10

"Derek O'Connor" <derekroconnor@eircom.net> wrote in message <hpj62l$k2v$1@fred.mathworks.com>...
> "James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <hpijmh$lv6$1@fred.mathworks.com>...
> > "Derek O'Connor" <derekroconnor@eircom.net> wrote in message <hpiiqc$8qe$1@fred.mathworks.com>...
> > >
> > > Unfortunately, IBM has just changed their policy and the public can no longer access their journals online.
> >
> > This seems to be an increasing problem in general. In this digital age, I am coming to believe that it is necessary to copy as much of this kind of stuff to personal storage somewhere so that I can retain access to it. What was once easy to get at online suddenly disappears.
> >
> > James Tursa
> >
> > btw ... thanks for the link ... I am currently copying it to my HD.
> ------------------------------------------------------------
>
> I'm still searching on my HDs and web for Moler & Morrison paper, but no luck so far.
>
> I wrote and tested this PythagSum algorithm in Fortran and Pascal many years ago but couldn't find them (on 5 1/4 inch floppies somewhere) so I translated the C version found on Steve Hollasch's site (above) into Matlab.
>
> I'm amazed how well it works: 1 to 3 iterations of the loop and it handles inputs x and y from 4.92e-324 to 1.27e+308 without under or overflow.
>
> sqrt(x^2 + y^2) is limited to 2.22e-162 to 6.70e+153.
>
> The function and tests are here:
> http://www.scribd.com/doc/29567048/TestPythagSum
>
>
> Derek O'Connor.

I found the Moler & Morrison paper on one of my hard disks, date-stamp 2005, when the IBM journals were publicly accessible. I've uploaded it to:

http://www.scribd.com/doc/29568822/Moler-Morrison-Ibmrd2706P

Derek O'Connor.

Subject: hypot( ) function?

From: Loren Shure

Date: 8 Apr, 2010 14:31:16

Message: 10 of 10

In article <gKGdnfpX1PxFhivWnZ2dnUVZ_qednZ2d@earthlink.com>,
jcrens@earthlink.net says...
> Anyone know anything about this function? I'm using an old version of
> Matlab (6), and it's used in a couple of my Simulink library blocks.
>
> Funny thing is, it's not shown as an m-file. The line "help hypot" turns
> up no match. Yet, it's there. If I type hypot([3,4]) I get 5.
>
> I think this must be the first time I've encountered an undocumented
> function in Matlab. That makes me curious about it. And it makes me
> wonder: what other neat little functions are hidden away in there?
>
> Jack
>

See my post from a while ago:

http://blogs.mathworks.com/loren/2008/02/07/why-hypot/

--
Loren
http://blogs.mathworks.com/loren
http://matlabwiki.mathworks.com/MATLAB_FAQ

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us