一、算术计算
命令行:
clear;
syms a b c d
a1 = a*b;a2 = b*c;a3 = c*d;a4 = d*a;
A = [a1 a2;a3 a4]
b1 = 2*a*b;b2 = d*a;b3 = 2*c*d;b4 = b*c;
B = [b1 b2;b3 b4]
C = A+B
D = [a*b b*c;c*d d*a]
E = [2*a*b d*a;2*c*d b*c]
F = D+E
输出:
>> Test
A =
[ a*b, b*c]
[ c*d, a*d]
B =
[ 2*a*b, a*d]
[ 2*c*d, b*c]
C =
[ 3*a*b, a*d + b*c]
[ 3*c*d, a*d + b*c]
D =
[ a*b, b*c]
[ c*d, a*d]
E =
[ 2*a*b, a*d]
[ 2*c*d, b*c]
F =
[ 3*a*b, a*d + b*c]
[ 3*c*d, a*d + b*c]
二、线性代数运算
命令行:
clear;
syms a b c d
a1 = a*b;a2 = b*c;a3 = c*d;a4 = d*a;
A = [a1 a2;a3 a4]
b1 = 2*a*b;b2 = d*a;b3 = 2*c*d;b4 = b*c;
B = [b1 b2;b3 b4]
C = A+B
Ct = C' #求C的转置矩阵
detC = det(C) #求C的行列式值
输出:
>> Test
A =
[ a*b, b*c]
[ c*d, a*d]
B =
[ 2*a*b, a*d]
[ 2*c*d, b*c]
C =
[ 3*a*b, a*d + b*c]
[ 3*c*d, a*d + b*c]
Ct =
[ 3*conj(a)*conj(b), 3*conj(c)*conj(d)]
[ conj(a)*conj(d) + conj(b)*conj(c), conj(a)*conj(d) + conj(b)*conj(c)]
detC =
3*a^2*b*d + 3*a*b^2*c - 3*a*c*d^2 - 3*b*c^2*d
三、eig:特征值分解
eig | 对符号矩阵进行特征值分解 |
---|
命令行:
clear
H = magic(3) %魔方三阶矩阵
H = sym(H)
[v,E] = eig(H)
digits(10) %设置计算精度为小数点后9位
[v1,E1] = eig(vpa(H)) %用vpa进行计算结果的数值精确
输出:
>> Test
H =
8 1 6
3 5 7
4 9 2
H =
[ 8, 1, 6]
[ 3, 5, 7]
[ 4, 9, 2]
v =
[ 1, - 24^(1/2)/5 - 7/5, 24^(1/2)/5 - 7/5]
[ 1, 24^(1/2)/5 + 2/5, 2/5 - 24^(1/2)/5]
[ 1, 1, 1]
E =
[ 15, 0, 0]
[ 0, 24^(1/2), 0]
[ 0, 0, -24^(1/2)]
v1 =
[ 0.5773502692, 0.8130525296, -0.3416480088]
[ 0.5773502692, -0.4714045208, -0.4714045208]
[ 0.5773502692, -0.3416480088, 0.8130525296]
E1 =
[ 15.0, 0, 0]
[ 0, 4.898979486, 0]
[ 0, 0, -4.898979486]