Why Power of Matrix with decimal values gives really big numbers?
Show older comments
Hello!
I've generated a matrix with decimal values using
T = rand(20);
And it looks like this:

However,
When I do
T^20
The answer I get is a matrix with really big numbers such as the following.

How come multiplications of decimal values give such great numbers? Is this correct? Is the command not doing what I think it is?
Thanks in advance,
2 Comments
"How come multiplications of decimal values give such great numbers?"
Because matrix power is defined as repeated matrix multiplication, and as any high-school student will tell you, that involves lots of summing as well as multiplication.
"Is this correct?"
Yes.
"Is the command not doing what I think it is? "
Possibly, but as you did not explain what you expect to happen, we don't know what the problem is. Possibly you did not pay attention to the differences between matrix operations (what you used) and array operations:
In order to use MATLAB you need to know the difference.
Alexandra Carvalho
on 7 Jan 2020
Accepted Answer
More Answers (3)
David Hill
on 7 Jan 2020
You need T.^20 for element-wise
T=T.^20;%you need the dot!
1 Comment
Alexandra Carvalho
on 7 Jan 2020
Star Strider
on 7 Jan 2020
It depends what you want to do. Note that ‘T^20’ multiplies the entire matrix by itself 20 times (although the actual algorithm uses the Cayley-Hamilton theorem to do the calculation).
Run this for an illustration:
T = rand(20);
Tn = T;
for k = 1:5
Tn = Tn * T;
k
D = Tn(1:5, 1:5)
end
If you want to raise the elements of ‘T’ each to the 20th power, use the dot operator to specify element-wise operations:
T20 = T.^20
That will give an entirely different result.
3 Comments
Alexandra Carvalho
on 7 Jan 2020
Star Strider
on 7 Jan 2020
You never mentioned that you are calculateing Markov chain probabilities in your original post.
Alexandra Carvalho
on 9 Jan 2020
Christine Tobler
on 8 Jan 2020
Edited: Christine Tobler
on 13 Jan 2020
For a Markov Chain, you need the sum of each row to be 1 (as this represents the probability to transition to any state), and every element of the matrix to be within 0 and 1. With the general random matrix you are using, that is not the case.
Try the following matrix:
A = rand(10);
A = A./sum(A, 2);
You can verify that sum(A, 2) is now all 1, and the same is true for sum(A^20, 2).
2 Comments
David Goodmanson
on 8 Jan 2020
Hi Christine,
looks like your statement that the sum of each column equals one is not conistent with sum(A,2).
Christine Tobler
on 13 Jan 2020
Right, I meant to say the sum of each row.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!