Complex conjugate: Difference between revisions

Delete my draft and #REDIRECT Arithmetic/Complex. I merged my own Factor and Ruby examples.
(Undo revision 131180 by Glennj (talk))
(Delete my draft and #REDIRECT Arithmetic/Complex. I merged my own Factor and Ruby examples.)
 
Line 1:
#REDIRECT [[Arithmetic/Complex]]
{{draft task}}
Given a [[Arithmetic/Complex|complex number]], find its [[wp:complex conjugate|complex conjugate]]. By definition, the complex conjugate of <math>a + bi</math> is <math>a - bi</math> (where <math>a</math> and <math>b</math> are real numbers, and <math>i</math> is the square root of -1).
 
Some languages have complex number libraries available. If possible, use your library's operation for complex conjugate.
 
=={{header|Factor}}==
<lang factor>USING: math.functions prettyprint ;
 
C{ 2 3 } conjugate . ! prints C{ 2 -3 }
C{ 4 -5 } conjugate . ! prints C{ 4 5 }</lang>
 
=={{header|Ruby}}==
<lang ruby>require 'complex' # With Ruby 1.9, this line is optional.
 
# Complex#conj or Complex#conjugate finds the conjugate.
i = Complex::I
puts (2 + 3*i).conj # 2-3i
puts (4 - 5*i).conjugate # 4+5i
 
# Numeric#conj or Numeric#conjugate returns self.
puts 67.conjugate # 67</lang>
Anonymous user