sqrt(sqrt(-1)) and m-files - maybe a bug?

sqrt(sqrt(-1)) and m-files - maybe a bug?

Post by AG » Wed, 19 Mar 2003 03:29:29



Hi

Has anyone come across the following before?

If I create a one line m-file sq.m with the contents

a = sqrt(sqrt(-1))

I get the (incorrect) answer

Quote:>> sq

a =

    0.7071

However if I type the same contents to the command line I get the
(correct) output

Quote:>> sqrt(sqrt(-1))

ans =

   0.7071 + 0.7071i

Any thoughts?

Thanks,
AG

 
 
 

sqrt(sqrt(-1)) and m-files - maybe a bug?

Post by kurt » Wed, 19 Mar 2003 03:51:02


I have replicated this. Similar wierd results for -2 etc. The correct
answer obtains when an inline function is used.

 
 
 

sqrt(sqrt(-1)) and m-files - maybe a bug?

Post by us » Wed, 19 Mar 2003 04:02:38


... even more puzzling

--- sq.m ---
b=sqrt(sqrt(-1))
--- sq.m ---

sq
b =
      0.70711
% now
dbstop if warning
b =
     0.70711 + 0.70711i

hmmm
us


> Has anyone come across the following before?

 
 
 

sqrt(sqrt(-1)) and m-files - maybe a bug?

Post by Penny Anderso » Wed, 19 Mar 2003 05:39:55


Yes, it is a known bug, fixed in R14 (not yet released).

http://www.mathworks.com/support/solutions/data/32599.shtml

Penny.

--
Penny Anderson, The MathWorks, Inc.


Quote:> Hi

> Has anyone come across the following before?

> If I create a one line m-file sq.m with the contents

> a = sqrt(sqrt(-1))

> I get the (incorrect) answer

> >> sq

> a =

>     0.7071

> However if I type the same contents to the command line I get the
> (correct) output

> >> sqrt(sqrt(-1))

> ans =

>    0.7071 + 0.7071i

> Any thoughts?

> Thanks,
> AG

 
 
 

sqrt(sqrt(-1)) and m-files - maybe a bug?

Post by us » Wed, 19 Mar 2003 05:53:13


very sad news for the sofware industry - at least, correct your tech
report!

as of now it says:
<<< quote tech rep beg >>>
Why does the SQRT function return incorrect results when it is called
in an M-file function as opposed to calling it from a MATLAB script
or the command line?
<<< quote tech rep end >>>

when, in fact, results are wrong if you use <sqrt>
- either within a script
- or a function

us


> Yes, it is a known bug, fixed in R14 (not yet released).

 <http://www.mathworks.com/support/solutions/data/32599.shtml>
 
 
 

1. bug sqrt



I just tried these 2 on one of our solaris machines and got a different
result from yours:

ans =

    42

ans =

  4.200000001000001e+01

ans =

SOL2



     24 Prime Park Way                http://www.mathworks.com
     Natick, MA 01760-1500                   ftp.mathworks.com
==== Tel: 508-647-7000 ===================== Fax: 508-647-7001 ====

2. stepper madness #2

3. On line 10 ==> y=sqrt(x^2+1);

4. Enabling Scripting with IE 6 viewing pics and gif files

5. Strange behaviour of Symbolic SQRT()

6. Time entry patch for AW3.0 exist?

7. why does matlab think -1 squared is -1

8. Interdev Shortcut Keys

9. z^-1

10. N(Z)*N(Z^-1) in Matlab?

11. Z and Z^(-1)

12. Where can i get XBF-neomagic-glibc-1.0.0-1.i386.rpm ?

13. Symbolic Toolbox: Display TF's in z^-1 format