Square Root

A

Angus Hammond

Is there a way to get an accurate square root?
This means that a negative number should return the appropriate complex
number. I have been having some trouble with this in a program that
solves quadratic equations recently. Ideally but not necessarily it
should be able to get the square root of complex numbers as well.
NB Neither -2**0.5 or Math::sqrt(-2) return appropriate answers. (-2 and
an error respectively)
Thanks in advance.
 
J

Jean-Julien Fleck

Hello Angus,

2010/5/29 Angus Hammond said:
Is there a way to get an accurate square root?
This means that a negative number should return the appropriate complex
number. I have been having some trouble with this in a program that solve= s
quadratic equations recently. Ideally but not necessarily it should be ab= le
to get the square root of complex numbers as well.
NB Neither -2**0.5 or Math::sqrt(-2) return appropriate answers. (-2 and = an
error respectively)

require 'complex'
include Math
c =3D Complex(-2,0)
sqrt(c)
=3D> Complex(0.0, 1.4142135623731)

Cheers,

--=20
JJ Fleck
PCSI1 Lyc=E9e Kl=E9ber
 
A

Angus Hammond

Thanks I had tried require complex and Math::sqrt but only separately.
Thanks again.
Angus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top