- Machine Learning with Spark(Second Edition)
- Rajdeep Dua Manpreet Singh Ghotra Nick Pentreath
- 277字
- 2021-07-09 21:07:47
Complex numbers
Our understanding is that the square of a number can never be negative. In that case, how do we solve x2 = -9? Sensibly, in math we have the concept of i, as a solution, that is, x = 3i. Numbers such as i, -i, 3i, and 2.27i are called imaginary numbers. "A real number" + "an imaginary number" forms a "complex number".
Complex number = (real part) + (imaginary part) I
The following examples show complex number representation using the Breeze library for Mathematics:
import breeze.linalg.DenseVector
import breeze.math.Complex
val i = Complex.i
// add
println((1 + 2 * i) + (2 + 3 * i))
// sub
println((1 + 2 * i) - (2 + 3 * i))
// divide
println((5 + 10 * i) / (3 - 4 * i))
// mul
println((1 + 2 * i) * (-3 + 6 * i))
println((1 + 5 * i) * (-3 + 2 * i))
// neg
println(-(1 + 2 * i))
// sum of complex numbers
val x = List((5 + 7 * i), (1 + 3 * i), (13 + 17 * i))
println(x.sum)
// product of complex numbers
val x1 = List((5 + 7 * i), (1 + 3 * i), (13 + 17 * i))
println(x1.product)
// sort list of complex numbers
val x2 = List((5 + 7 * i), (1 + 3 * i), (13 + 17 * i))
println(x2.sorted)
This preceding code gives us the following result:
3.0 + 5.0i
-1.0 + -1.0i
-1.0 + 2.0i
-15.0 + 0.0i
-13.0 + -13.0i
-1.0 + -2.0i
19.0 + 27.0i
-582.0 + 14.0i
List(1.0 + 3.0i, 5.0 + 7.0i, 13.0 + 17.0i)
推薦閱讀
- Hands-On Intelligent Agents with OpenAI Gym
- 課課通計算機原理
- Learning Social Media Analytics with R
- JMAG電機電磁仿真分析與實例解析
- 大數(shù)據(jù)平臺異常檢測分析系統(tǒng)的若干關(guān)鍵技術(shù)研究
- CompTIA Network+ Certification Guide
- 悟透JavaScript
- R Machine Learning Projects
- C++程序設(shè)計基礎(chǔ)(上)
- 常用傳感器技術(shù)及應(yīng)用(第2版)
- Getting Started with Tableau 2018.x
- 中小型網(wǎng)站建設(shè)與管理
- Mastering Windows Group Policy
- Practical Autodesk AutoCAD 2021 and AutoCAD LT 2021
- 大學計算機實踐教程