Complex Numbers |
Complex Numbers are the members of set C, of the form
x + iy, where x and y are real numbers and i is the
imaginary unit equal to the square-root of -1,
.
Complex conjugate of z = x + iy is
=
x – iy.
Two complex numbers z1 = a + ib and z2 = c + id are added together component wise,
Two complex numbers z1 = a + ib and z2 = c + id are multiplied as follows,
z1 z2 = (a + ib)(c + id) = ac + ibc + iad –bd = (ac – bd) + i(ad + bc)
Complex multiplication can be carried out using only three real multiplications, ac, bd, and (a+b)(c+d), as
Real Part of Complex Product = (ac – bd)
Complex Part of Complex Product = (a + b)(c + d) – ac – bd
Division of two complex numbers can be accomplished by multiplying the numerator and denominator by the complex conjugate of the denominator, e.g. with z1 = a + bi and z2 = c + di,
![]()
os_num_complex class provides the capability to represent and manipulate complex numbers. os_num_complex class can be used as the type for other templatized Math<Toolkit> classes for Vectors, Matrices and N-Dimensional arrays.
The example code below shows how to use various methods supported by the os_num_complex class. One can notice that some of the methods below are also being passed the expected value to verify that the operation is yielding the right results.
#include <ospace/math.h>
int
main()
{
os_math_toolkit math_init;
const double TEST_A = 2;
os_num_complex< double > cmplx_x( 5.0, 0.0 );
os_num_complex< double > cmplx_y( 3.0, 2.0 );
os_num_complex< double > cmplx_z;
cout << "===== complex contents =====" << endl;
cout << "complex x = " << cmplx_x << endl;
cout << "complex y = " << cmplx_y << endl;
cout << "complex z = " << cmplx_z << endl;
cout << "===== basic scalar ops =====" << endl;
cmplx_z = cmplx_x + TEST_A;
cout << "z=x+a = " << cmplx_z << endl;
cmplx_z = cmplx_x - TEST_A;
cout << "z=x-a = " << cmplx_z << endl;
cmplx_z = cmplx_x * TEST_A;
cout << "z=x*a = " << cmplx_z << endl;
cmplx_z = cmplx_x / TEST_A;
cout << "z=x/a = " << cmplx_z << endl;
cout << "===== basic complex ops =====" << endl;
cmplx_z = cmplx_x + cmplx_y;
cout << "z=x+y = " << cmplx_z << endl;
cmplx_z = cmplx_x - cmplx_y;
cout << "z=x-y = " << cmplx_z << endl;
cmplx_z = cmplx_x * cmplx_y;
cout << "z=x*y = " << cmplx_z << endl;
cmplx_z = cmplx_x / cmplx_y;
cout << "z=x/y = " << cmplx_z << endl;
cout << "===== complex ops =====" << endl;
cmplx_z = cmplx_x * cmplx_y + cmplx_x / cmplx_y - cmplx_x * cmplx_y;
cout << "z=x*y+x/y-x*y = " << cmplx_z << endl;
return 0;
}
Copyright©1994-2013 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.