One of the three mathematics software, math class science and technology applications in numerical terms acclaimed MATLAB R2018b for Mac application and its wide, now it brings Mac in basic matrix operations MATLAB R2018b for small partners who want to help to everyone!
The following example illustrates the basic methodology and functions to MATLAB® language processing matrices.
First, create a file called a simple vector and contains nine elements.
a = [1 2 3 4 6 4 3 4 5]
a =1×91 2 3 4 6 4 3 4 5
Now, for each element of vector a plus 2, and the result is stored in a new vector.
Note MATLAB vector or matrix operations does not require special handling.
b = a + 2
b =1×93 4 5 6 8 6 5 6 7
Create graphics as easy as execute a command in MATLAB. Followed by grid lines drawn vector and results.
plot(b) grid on
MATLAB can also create additional chart types include axis labels.
bar(b) xlabel('Sample #') ylabel('Pounds')
MATLAB notation can also be used in the drawing. The following is a marked with an asterisk each sample point. MATLAB provides a variety of symbols and line types.
plot(b,'*') axis([0 10 0 10])
One aspect of MATLAB excels is matrix calculations.
Create a matrix just as easy to create a vector, you can use a semicolon (;) separating each row of the matrix.
A = [1 2 0; 2 5 -1; 4 10 -1]
A =3×31 2 0 2 5 -1 4 10 -1
可以很容易地计算矩阵 A 的转置。
B = A'
B =3×31 2 4 2 5 10 0 -1 -1
接下来,将这两个矩阵相乘。
同样请注意,MATLAB 不要求像处理数据集合一样处理矩阵。MATLAB 知道您正在处理矩阵并相应调整您的计算。
C = A * B
C =3×35 12 24 12 30 59 24 59 117
无需执行矩阵相乘,使用 .* 运算符即可将两个矩阵或向量的对应元素相乘。
C = A .* B
C =3×31 4 0 4 25 -10 0 -10 1
使用矩阵 A 对方程 A*x = b 求解,方法是使用 \(反斜杠)运算符。
b = [1;3;5]
b =3×11 3 5
x = A\b
x =3×11 0 -1
现在可以显示 A*x 等于 b。
r = A*x - b
r =3×10 0 0
MATLAB 拥有几乎所有用于常见矩阵计算的函数。
有用于获取特征值的函数...
eig(A)
ans =3×13.7321 0.2679 1.0000
...以及用于获取奇异值的函数。
svd(A)
ans =3×112.3171 0.5149 0.1577
“poly”函数生成特征多项式系数的向量。
矩阵 A 的特征多项式为
p = round(poly(A))
p =1×41 -5 5 -1
使用 roots 函数很容易确定多项式的根。
这些值实际上是原始矩阵的特征值。
roots(p)
ans =3×13.7321 1.0000 0.2679
除了矩阵计算之外,MATLAB 还有许多其他应用。
求两个向量的卷积...
q = conv(p,p)
q =1×71 -10 35 -52 35 -10 1
...或再次求卷积并绘制结果图。
r = conv(p,q)
r =1×101 -15 90 -278 480 -480 278 -90 15 -1
plot(r);
使用 who 或 whos 命令可随时获取内存中存储的变量列表。
whos
Name Size Bytes Class Attributes
A 3x3 72 double
B 3x3 72 double
C 3x3 72 double
a 1x9 72 double
ans 3x1 24 double
b 3x1 24 double
p 1x4 32 double
q 1x7 56 double
r 1x10 80 double
x 3x1 24 double
You can get the value of this variable by typing the name of a specific variable.
A
A =3×31 2 0 2 5 -1 4 10 -1
Each row can have more than one statement, using a comma or semicolon separated individual statements.
If the variable is not specified result to the store operation, the result stored in the temporary variable named in ans.
sqrt(-1)
ans = 0.0000 + 1.0000i
As can be seen, MATLAB easy to handle in a plurality of calculation.