# Addition Of Diagonal Elements Of A Matrix In MatLab®(Illustrated Expression)

In this article, we will show another linear algebra command of Matlab® that adds the diagonal elements of a matrix. You know already that Matlab® has lots of special commands about linear algebra that Mechanicalland includes all of them as an article like this.

Also, you can find lots of content about Matlab® like this article in Mechanicalland to learn Matlab® completely. Visit the main page of Mechanicalland!

On this post

## How To Add Diagonal Elements Of A Matrix In MatLab®?

``````>> a = [1 3 5; 7 8 11; 100 1 4]
b = trace(a)
c = trace(a)*5
d = trace(a)^3

a =

1     3     5
7     8    11
100     1     4

b =

13

c =

65

d =

2197

>> a = [1 3 5; 7 8 11; 100 1 4]
b = trace(a)
c = trace(a)*5
d = trace(a)^3

a =

1     3     5
7     8    11
100     1     4

b =

13

c =

65

d =

2197

a =

1     3     5
7     8    11
100     1     4

b =

13

c =

65

d =

2197
``````

To add the diagonal values of matrix ‘a’, we need to use the trace(a) command to do it in Matlab®.

For example ‘b’ is the diagonal addition value of matrix ‘a’ obtained with trace() command as shown above in Matlab®.

‘c’ is the multiplication of diagonal addition value of matrix ‘a’ with 5 that shows it is possible to make mathematical calculations with diagonal addition values of matrices as shown above in Matlab®.

‘d’ is the exponentiated value of diagonal summation of the matrix ‘a’ with 3 that also shows all of the mathematical calculations are valid for trace() command in Matlab®.

## Conclusion

So it is very easy to take the diagonal summations of matrices in Matlab® with trace() command.

Do not forget to leave your comments and questions below about the use of trace() command in Matlab® below.

If you want further coding examples about the trace() command in Matlab®, inform us in the comments.