In this post I discuss some of the new features in MATLAB R2021a. As usual in this series, I focus on a few of the features most relevant to my interests. See the release notes for a detailed list of the many changes in MATLAB and its toolboxes.
In function calls that accept “name, value” pairs, separated by a comma, the values can now be specified with an equals sign. Example:
x = linspace(0,2*pi,100); y = tan(x); % Existing syntax plot(x,y,'Color','red','LineWidth',2) plot(x,y,"Color","red","LineWidth",2) % New syntax plot(x,y,Color = "red",LineWidth = 2) lw = 2; plot(x,y,Color = "red",LineWidth = lw)
Note that the string can be given as a character vector in single quotes or as a string array in double quotes (string arrays were introduced in R2016b).
There are some limitations, including that all name=value arguments must appear after any comma separated pairs and after any positional arguments (arguments that must be passed to a function in a specific order).
Eigensystem of Skew-Symmetric Matrix
For skew-symmetric and skew-Hermitian matrices, the
eig function now guarantees that the matrix of eigenvectors is unitary (to machine precision) and that the computed eigenvalues are pure imaginary. The code
rng(2); n = 5; A = gallery('randsvd',n,-1e3,2); A = 1i*A; [V,D] = eig(A); unitary_test = norm(V'*V-eye(n),1) norm_real_part = norm(real(D),1)
% R2020b unitary_test = 9.6705e-01 norm_real_part = 8.3267e-17 % R2021a unitary_test = 1.9498e-15 norm_real_part = 0
For this matrix MATLAB R2020b produces an eigenvector matrix that is far from being unitary and eigenvalues with a nonzero (but tiny) real part, whereas MATLAB R2021a produces real eigenvalues and eigenvectors that are unitary to machine precision.
Among the reported performance improvements are faster matrix multiplication for large sparse matrices and faster solution of multiple right-hand systems with a sparse coefficient matrix, both resulting from added support for multithreading.
Symbolic Math Toolbox
An interesting addition to the Symbolic Math Toolbox is the
symmatrix class, which represents a symbolic matrix. An example of usage is
>> A = symmatrix('A',[2 2]); B = symmatrix('B',[2 2]); whos A B Name Size Bytes Class Attributes A 2x2 8 symmatrix B 2x2 8 symmatrix >> X = A*B, Y = symmatrix2sym(X), whos X Y X = A*B Y = [A1_1*B1_1 + A1_2*B2_1, A1_1*B1_2 + A1_2*B2_2] [A2_1*B1_1 + A2_2*B2_1, A2_1*B1_2 + A2_2*B2_2] Name Size Bytes Class Attributes X 2x2 8 symmatrix Y 2x2 8 sym
The range of functions that can be applied to a
symmatrix is as follows:
>> methods symmatrix Methods for class symmatrix: adjoint horzcat mldivide symmatrix cat isempty mpower symmatrix2sym conj isequal mrdivide tan cos isequaln mtimes times ctranspose kron norm trace det latex plus transpose diff ldivide power uminus disp length pretty uplus display log rdivide vertcat eq matlabFunction sin exp minus size Static methods: empty
In order to invert
A*B in this example, or find its eigenvalues, use