Substitute Elements in Symbolic Matrices

Create a 3-by-3 circulant matrix using the backward shift.

syms a b c
M = [a b c; b c a; c a b]
M =
[ a, b, c]
[ b, c, a]
[ c, a, b]

Replace variable b in this matrix by the expression a + 1. The subs function replaces all b elements in matrix M with the expression a + 1.

M = subs(M, b, a + 1)
M =
[     a, a + 1,     c]
[ a + 1,     c,     a]
[     c,     a, a + 1]

You also can specify the value to replace by indexing into matrix. That is, to replace all elements whose value is c, you can specify the value to replace as c, M(1,3) or M(3,1).

Replace all elements whose value is M(1,3) = c with the expression a + 2.

M = subs(M, M(1,3), a + 2)
M =
[     a, a + 1, a + 2]
[ a + 1, a + 2,     a]
[ a + 2,     a, a + 1]

Tip

To replace a particular element of a matrix with a new value while keeping all other elements unchanged, use the assignment operation. For example, M(1,1) = 2 replaces only the first element of the matrix M with the value 2.

Find eigenvalues and eigenvectors of the matrix.

[V,E] = eig(M)
V =
[ 1,   3^(1/2)/2 - 1/2, - 3^(1/2)/2 - 1/2]
[ 1, - 3^(1/2)/2 - 1/2,   3^(1/2)/2 - 1/2]
[ 1,                 1,                 1]
 
E =
[ 3*a + 3,       0,        0]
[       0, 3^(1/2),        0]
[       0,       0, -3^(1/2)]

Replace the symbolic parameter a with the value 1.

subs(E, a, 1)
ans =
[ 6,       0,        0]
[ 0, 3^(1/2),        0]
[ 0,       0, -3^(1/2)]