【功能简介】用实部和虚部创建复数。
【语法格式】
1.c=complex(a,b)
用两个实数a和b创建复数c,c=a+bi。c与a、b是同型的数组或矩阵。如果b是全零的,c也依然是一个复数,例如,c=complex(1,0)返回复数1,isreal(c)等于false,而1+0i则返回实数1。
2.c=complex(a)
输入参数a作为复数c的实部,c的虚部为零,但isreal(a)返回false,表示c是一个复数。
【实例5.28】创建复数3+4i和2+0i。
- >> a=complex(3,4) %创建复数3+4i
- a =
- 3.0000 + 4.0000i
- >> b=complex(2,0) %用complex创建复数2+0i
- b =
- 2
- >> c=2+0i %直接创建复数2+0i
- c =
- 2
- >> b==c %b的值与c相等
- ans =
- 1
- >> isreal(b) %b是复数
- ans =
- 0
- >> isreal(c) %c是实数
- ans =
- 1
【实例分析】虽然b与c相等,但b是由complex创建的,属于复数,c则是实数。