Creating Diagonal Matrices With A Vector Elements In MatLab(Illustrated Expression)

There are lots of kinds of commands in Matlab to make easy to obtain various specific matrices in short way. So this feature of MatLab, make the MatLab software is ver desirable for matrix calculations. One of these useful matrix creation command in Matlab is ‘diag()’ command. In this article we will explain how to create diagonal matrices by using elements of a vector in Matlab.

How To Use ‘diag()’ Command In Matlab?

Use of ‘diag()’ command in Matlab.

We created a vector ‘a’ as shown by red arrow above to create a diagonal matrix by using this vector. So we directly use the vector ‘a’ to create the diagonal matrix of ‘b’ as shown by green arrow. If you look at the result of the ‘b’ as shown in green box above, a diagonal matrix is created with elements of vector ‘a’ as diagonal elements. So you can directly use a vector variable inside the ‘diag()’ command in Matlab.

Also we created diagınal matrix ‘c’ as shown by blue arrow above. If you look at the result of ‘c’ as shown by red box above, the diagonal matrix of ‘c’ is created with the elements of vector that typed inside the ‘diag()’ command as shown by blue arrow. So you can directly type the vector inside the ‘diag()’ command to obtain diagonal matrices in Matlab.

So the use of ‘diag()’ command in Matlab is very simple like that to obtain diagonal matrices.

Leave your comments and questions below!

Share This Post! Share Tweet Share

Write your comment on this topic.