Matlab学习20181015
perms
>> help perms
PERMS All possible permutations. %所有的排列组合
PERMS(1:N), or PERMS(V) where V is a vector of length N, creates a
matrix with N! rows(行) and N columns(列) containing all possible
permutations of the N elements.
This function is only practical(可行) for situations where N s less
than about 10 (for N=11, the output takes over 3 giga-bytes(十亿字节=GB)).
Class support for input V:
float: double, single
See also nchoosek, randperm, permute.
Reference page in Help browser
doc perms
如下
>> perms(0:2) %返回0 1 2 的排列的所有情况
ans =
2 1 0
2 0 1
1 2 0
1 0 2
0 1 2
0 2 1
a(:,i)、a(i,:)
>> a=magic(10)
a =
92 99 1 8 15 67 74 51 58 40
98 80 7 14 16 73 55 57 64 41
4 81 88 20 22 54 56 63 70 47
85 87 19 21 3 60 62 69 71 28
86 93 25 2 9 61 68 75 52 34
17 24 76 83 90 42 49 26 33 65
23 5 82 89 91 48 30 32 39 66
79 6 13 95 97 29 31 38 45 72
10 12 94 96 78 35 37 44 46 53
11 18 100 77 84 36 43 50 27 59
>> a(1:2:9,1:2:9) %第1、3、5、7、9行与第1、3、5、7、9列重叠的部分返回
ans =
92 1 15 74 58
4 88 22 56 70
86 25 9 68 52
23 82 91 30 39
10 94 78 37 46
>> a(:,1) %返回第一列
ans =
92
98
4
85
86
17
23
79
10
11
>> a(1,:) %返回第一行
ans =
92 99 1 8 15 67 74 51 58 40
matlab中的subscript与linear index;sub2ind与ind2sub
subscript:数组的下标
linear index:数组存储方式是从上往下,从左往右的方式
>> A = [2 6 9; 4 2 8; 3 5 1]
A =
2 6 9
4 2 8
3 5 1
>> linearindex = sub2ind(size(A), 3, 2) %把下标变为linear index
linearindex =
6
>> A = [2 6 9; 4 2 8; 3 5 1]
A =
2 6 9
4 2 8
3 5 1
>> [i j]=ind2sub(size(A),8) %返回形状如矩阵A所示的矩阵,linearindex=8的subscript
i =
2
j =
3
find
>> a=[1 2 3 0;5 -6 7 -8;9 0 -6 -7;-8 2 4 0];
>> a
a =
1 2 3 0
5 -6 7 -8
9 0 -6 -7
-8 2 4 0
>> find(a) %返回a中不为0的位置索引(linear indices)
ans =
1
2
3
4
5
6
8
9
10
11
12
14
15
>> find(a,8) %=find(a,8,‘first’) 返回前八个不为零的位置索引
ans =
1
2
3
4
5
6
8
9
>> find(a,8,'last') %返回后八个不为零的位置索引
ans =
6
8
9
10
11
12
14
15
>> a=magic(3)
a =
8 1 6
3 5 7
4 9 2
>> find(a>5) %返回a中元素大于5的位置索引
ans =
1
6
7
8
linspace(a,b)、logspace(a,b)
>> linspace(0,99) %[0,99]的区间内取100个等分点,步长h=(99-0)/99
ans =
Columns 1 through 27
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
Columns 28 through 54
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
Columns 55 through 81
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
Columns 82 through 100
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
>> linspace(-3,3,7) %第三个参数没有时,默认是100个
ans =
-3 -2 -1 0 1 2 3
>> logspace(0,10,11) %以10为底,指数:0,1,2,3,4,5,6,7,8,9,10共十一个点;第三个参数没有时默认为50
ans =
1.0e+010 *
Columns 1 through 5
0.000000000100000 0.000000001000000 0.000000010000000 0.000000100000000 0.000001000000000
Columns 6 through 10
0.000010000000000 0.000100000000000 0.001000000000000 0.010000000000000 0.100000000000000
Column 11
1.000000000000000
多项式估值polyval(p,x)
>> x=linspace(-3,3);
>> p=[1 2 3 4];
>> y=poly2sym(p)
y =
x^3 + 2*x^2 + 3*x + 4
>> v=polyval(p,x); %求以p为系数的多项式在x处的多项式值
部分分式展开residue(A,B)或则和residue(r,p,k)、polyder(A,B)有理式求导
[r,p,k] = residue(b,a) 计算以如下形式展开的两个多项式之比的 部分分式展开 的留数res、极点poles和直项k
>> num=10*[1 2]
num =
10 20
>> den=poly([-1;-3;-4])
den =
1 8 19 12
>> poly2sym(den)
ans =
x^3 + 8*x^2 + 19*x + 12
>> [r p k]=residue(num,den)
r =
-6.6667
5.0000
1.6667
p =
-4.0000
-3.0000
-1.0000
k =
[]
>> [num,den]=residue(r,p,k) %residue也可以执行逆运算
num =
-0.0000 10.0000 20.0000
den =
1.0000 8.0000 19.0000 12.0000
>> [b,a]=polyder(num,den) %polyder输入两个参数时,是对多项式求导,返回分子分母多项式的系数
b =
0.0000 -20.0000 -140.0000 -320.0000 -260.0000
a =
1.0000 16.0000 102.0000 328.0000 553.0000 456.0000 144.0000
feval 函数
>> syms x
>> fun=@(x)(x^(-2)+x); %定义函数
>> feval(fun,1)
ans =
2