complex number code
func arrayComplexElementsProduct(real: [Int], imag: [Int]) -> [Int] {
var x = real[0]
var y = imag[0]
for i in 1..<real.count {
let a = x*real[i] - y*imag[i]
let b = x*imag[i] + y*real[i]
x = a
y = b
}
return [x,y]
}
var x = real[0]
var y = imag[0]
for i in 1..<real.count {
let a = x*real[i] - y*imag[i]
let b = x*imag[i] + y*real[i]
x = a
y = b
}
return [x,y]
}
Comments
Post a Comment