>> clear
>> cd D:\mydir %将用户目录设置成当前目录
>> path (path ,'D:/mydir') %将用户目录D:\mydir加大搜索路径下
>> %
>> %数组与矩阵
>> %
>> %例1
>> a=1:5
a =
1 2 3 4 5
>> a=1:2:10
a =
1 3 5 7 9
>> %x = linspace(first,last,n) 线性等分创建数组,返回以first为初值,last为终值的等间距的n 个元素
>> a = linspace(0,1,5)
a =
0 0.2500 0.5000 0.7500 1.0000
>> %x = logspace(first,last,n)
>> % 对数等分创建数组,返回以10 的first次方为初值,10的last次方为终值的n 个元素,并且这n个元素的对数值是等间距的,
>> %相当于这n 个元素为10.^linspace(first,last,n)
>> b = 10.^a
b =
1.0000 1.7783 3.1623 5.6234 10.0000
>> c = logspace(0,1,5)
c =
1.0000 1.7783 3.1623 5.6234 10.0000
>> %数组元素的访问
>> %例4
>> d = a([1,2,3,5]) %提取数组的第1,2,3,5个元素构成新的数组
d =
0 0.2500 0.5000 1.0000
>> %元素以空格或逗号分隔,创建的是行向量;以分号分隔,创建的是列向量。
>> c = [1,3,5,7,9]
c =
1 3 5 7 9
>> f = [1;3;5;7]
f =
1
3
5
7
>> A = [1 2 3;4 5 6; 7 8 9;]
A =
1 2 3
4 5 6
7 8 9
>> %什么是共轭转置
>> c = [1+i,1;2-i,2];
>> d = c' %共轭转置
d =
1.0000 - 1.0000i 2.0000 + 1.0000i
1.0000 + 0.0000i 2.0000 + 0.0000i
>> e = c.'
e =
1.0000 + 1.0000i 2.0000 - 1.0000i
1.0000 + 0.0000i 2.0000 + 0.0000i
>>
>> A = [1,2,3;4,5,6]
A =
1 2 3
4 5 6
>> C = 5
C =
5
>> A + C
ans =
6 7 8
9 10 11
>> B = [2,4,6;3,5,7]
B =
2 4 6
3 5 7
>> A.*B
ans =
2 8 18
12 25 42
>> A.*C
ans =
5 10 15
20 25 30
>> %例9
>> A = [1 2 0;2 5 -1;4 10 -1];
>> eig(A) %求A的特征值
ans =
3.7321
0.2679
1.0000
>> [x,y]=eig(A)
x =
-0.2440 -0.9107 0.4472
-0.3333 0.3333 0.0000
-0.9107 -0.2440 0.8944
y =
3.7321 0 0
0 0.2679 0
0 0 1.0000
>> %上面是X特征向量方阵 和 Y特征向量方阵