matlab基础学习(1)
在matlab中输入如下命令的结果:>> help j
J Imaginary unit.
As the basic imaginary unit SQRT(-1), i and j are used to enter
complex numbers. For example, the expressions 3+2i, 3+2*i, 3+2j,
3+2*j and 3+2*sqrt(-1) all have the same value.
Since both i and j are functions, they can be overridden and used
as a variable. This permits you to use i or j as an index in FOR
loops, subscripts, etc.
See also i.
Reference page in Help browser
doc j
>> help i
I Imaginary unit.
As the basic imaginary unit SQRT(-1), i and j are used to enter
complex numbers. For example, the expressions 3+2i, 3+2*i, 3+2j,
3+2*j and 3+2*sqrt(-1) all have the same value.
Since both i and j are functions, they can be overridden and used
as a variable. This permits you to use i or j as an index in FOR
loops, etc.
See also j.
Reference page in Help browser
doc i
>> sqrt(-1)
ans =
0 + 1.0000i
>> help real
REAL Complex real part.
REAL(X) is the real part of X.
See I or J to enter complex numbers.
See also isreal, imag, conj, angle, abs.
Overloaded functions or methods (ones with the same name in other directories)
help frd/real.m
help sym/real.m
help iddata/real.m
Reference page in Help browser
doc real
>> help imag
IMAG Complex imaginary part.
IMAG(X) is the imaginary part of X.
See I or J to enter complex numbers.
See also real, isreal, conj, angle, abs.
Overloaded functions or methods (ones with the same name in other directories)
help frd/imag.m
help sym/imag.m
help iddata/imag.m
Reference page in Help browser
doc imag
>> help conj
CONJ Complex conjugate.
CONJ(X) is the complex conjugate of X.
For a complex X, CONJ(X) = REAL(X) - i*IMAG(X).
See also real, imag, i, j.
Overloaded functions or methods (ones with the same name in other directories)
help zpk/conj.m
help tf/conj.m
help ss/conj.m
help sym/conj.m
Reference page in Help browser
doc conj
>> help abs
ABS Absolute value.
ABS(X) is the absolute value of the elements of X. When
X is complex, ABS(X) is the complex modulus (magnitude) of
the elements of X.
See also sign, angle, unwrap, hypot.
Overloaded functions or methods (ones with the same name in other directories)
help frd/abs.m
help sym/abs.m
help iddata/abs.m
Reference page in Help browser
doc abs
>> help angle
ANGLE Phase angle.
ANGLE(H) returns the phase angles, in radians, of a matrix with
complex elements.
Class support for input X:
float: double, single
See also abs, unwrap.
Overloaded functions or methods (ones with the same name in other directories)
help frd/angle.m
help iddata/angle.m
Reference page in Help browser
doc angle
以下是使用上述命令的例子:
>> x = 1
x =
1
>> y = 2;
>> z = x + j * y
z =
1.0000 + 2.0000i
>> 1/z
ans =
0.2000 - 0.4000i
>> z^2
ans =
-3.0000 + 4.0000i
>> real(z)
ans =
1
>> imag(z)
ans =
2
>> conj(z)
ans =
1.0000 - 2.0000i
>> z*conj(z)
ans =
5
>> abs(z)
ans =
2.2361
>> abs(z)^2
ans =
5.0000
>> angle(z)
ans =
1.1071
>>
注:在matlab中缺省没有对e进行定义,不过我们可以通过 e= exp(1)计算得到,如下
>> e = exp(1)
e =
2.7183
>>
复数的极坐标表示如下:>> z = 1 + j * 2
z =
1.0000 + 2.0000i
>> r = abs(z)
r =
2.2361
>> theta = angle(z)
theta =
1.1071
>> r * exp(j*theta)
ans =
1.0000 + 2.0000i
以下是一些比较有意思的操作:>> z = 1 + j* 2
z =
1.0000 + 2.0000i
>> z/conj(z)
ans =
-0.6000 + 0.8000i
>> theta = angle(z)
theta =
1.1071
>> exp(2*j*theta)
ans =
-0.6000 + 0.8000i
>> imag(log(z/abs(z)))
ans =
1.1071
>> theta
theta =
1.1071
>>
在matlab语法中另一个需要注意的问题是转置操作符'(对于矢量和矩阵)。
当是'符号时,进行共轭转置。
而当是.'时,进行转置,但没有共轭。
如下例所示:
>> x = [1:4]*j
x =
0 + 1.0000i 0 + 2.0000i 0 + 3.0000i 0 + 4.0000i
>> x'
ans =
0 - 1.0000i
0 - 2.0000i
0 - 3.0000i
0 - 4.0000i
>> x.'
ans =
0 + 1.0000i
0 + 2.0000i
0 + 3.0000i
0 + 4.0000i
>>