Prev: Inject Loop Syntax
Next: How to load code converters?
From: Angus Hammond on 29 May 2010 15:56 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.
From: Jean-Julien Fleck on 29 May 2010 16:03 Hello Angus, 2010/5/29 Angus Hammond <angushammond(a)hotmail.co.uk>: > 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) require 'complex' include Math c = Complex(-2,0) sqrt(c) >> require 'complex' => true >> include Math => Object >> c = Complex(-2,0) => Complex(-2, 0) >> sqrt(c) => Complex(0.0, 1.4142135623731) Cheers, -- JJ Fleck PCSI1 Lycée Kléber
From: Angus Hammond on 29 May 2010 16:33 Thanks I had tried require complex and Math::sqrt but only separately. Thanks again. Angus On 29/05/10 21:03, Jean-Julien Fleck wrote: > Hello Angus, > > 2010/5/29 Angus Hammond<angushammond(a)hotmail.co.uk>: > >> 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) >> > require 'complex' > include Math > c = Complex(-2,0) > sqrt(c) > > >>> require 'complex' >>> > => true > >>> include Math >>> > => Object > >>> c = Complex(-2,0) >>> > => Complex(-2, 0) > >>> sqrt(c) >>> > => Complex(0.0, 1.4142135623731) > > Cheers, > >
From: jzakiya on 2 Jun 2010 12:45 On May 29, 3:33 pm, Angus Hammond <angushamm...(a)hotmail.co.uk> wrote: > Thanks I had tried require complex and Math::sqrt but only separately. > Thanks again. > Angus > > On 29/05/10 21:03, Jean-Julien Fleck wrote: > > > Hello Angus, > > > 2010/5/29 Angus Hammond<angushamm...(a)hotmail.co.uk>: > > >> 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) > > > require 'complex' > > include Math > > c = Complex(-2,0) > > sqrt(c) > > >>> require 'complex' > > > => true > > >>> include Math > > > => Object > > >>> c = Complex(-2,0) > > > => Complex(-2, 0) > > >>> sqrt(c) > > > => Complex(0.0, 1.4142135623731) > > > Cheers, > > FYI. For more extensive (and easy) way to add the ability to find the nth roots of all numerical types check out my Roots module here: http://gist.github.com/422636 Jabari
|
Pages: 1 Prev: Inject Loop Syntax Next: How to load code converters? |