當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Ruby Complex conjugate()用法及代碼示例


Complex#conjugate()是Complex類方法,它返回複數值的共軛部分。

用法:Complex.conjugate()

參數:複數值


返回:複數值的共軛部分。

示例1:

# Ruby code for Complex.conjugate() method 
  
# declaring Complex value 
a = Complex(200) 
  
# declaring Complex value 
b = Complex(-1, 4) 
  
# declaring Complex value 
c = Complex('i') 
  
  
# use of conjugate()   
puts "Complex conjugate form : #{a.conjugate}\n\n"
  
puts "Complex conjugate form : #{b.conjugate}\n\n"
  
puts "Complex conjugate form : #{c.conjugate}\n\n"

輸出:

Complex conjugate form : 200+0i

Complex conjugate form : -1-4i

Complex conjugate form : 0-1i

示例2:

# Ruby code for Complex.conjugate() method 
  
# declaring Complex value 
a = Complex(20, 90) 
  
# declaring Complex value 
b = Complex('i') 
  
# declaring Complex value 
c = Complex(100, -500) 
  
# use of conjugate()   
puts "Complex conjugate form : #{a.conjugate}\n\n"
  
puts "Complex conjugate form : #{b.conjugate}\n\n"
  
puts "Complex conjugate form : #{c.conjugate}\n\n"

輸出:

Complex conjugate form : 20-90i

Complex conjugate form : 0-1i

Complex conjugate form : 100+500i



相關用法


注:本文由純淨天空篩選整理自Kirti_Mangal大神的英文原創作品 Ruby | Complex conjugate() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。