Why Power of Matrix with decimal values gives really big numbers?

조회 수: 6 (최근 30일)
Hello!
I've generated a matrix with decimal values using
T = rand(20);
And it looks like this:
matlb.PNG
However,
When I do
T^20
The answer I get is a matrix with really big numbers such as the following.
matlb.PNG
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
Stephen23
Stephen23 2020년 1월 7일
편집: Stephen23 2020년 1월 7일
"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
Alexandra Carvalho 2020년 1월 7일
I know the difference and I want to multiply the matrix by itself 20 times. I don't want to do it element-wise. Thank you very much for nothing :(
I'm looking into Markov Chains and the matrix represents transition probabilities. These should never pass the value 1. Also, these probabilities are supposed to stabilize given a large enough n. Every exercise I tried is giving me correct values apart from this one.

댓글을 달려면 로그인하십시오.

채택된 답변

John D'Errico
John D'Errico 2020년 1월 7일
편집: John D'Errico 2020년 1월 7일
This is basic linear algebra. I think you do not understand what is happening, or perhaps you do not understand Markov transition matrices. Something along those lines. For example...
R = rand(20);
eig(R)
ans =
9.8584 + 0i
0.3537 + 1.1913i
0.3537 - 1.1913i
-1.1665 + 0.26994i
-1.1665 - 0.26994i
-0.71294 + 0.74919i
-0.71294 - 0.74919i
-0.80233 + 0.054562i
-0.80233 - 0.054562i
-0.10344 + 0.80806i
-0.10344 - 0.80806i
0.8188 + 0.37927i
0.8188 - 0.37927i
0.69076 + 0i
0.62369 + 0i
0.40071 + 0.42737i
0.40071 - 0.42737i
-0.34121 + 0i
0.034137 + 0.41554i
0.034137 - 0.41554i
As it turns out, there is one direction that corresponds to a large eigenvalue. So when we raise R to high powers, we see R^20, for example, has huge numbers.
max(R^20,[],'all')
ans =
5.9807e+18
But is R a markov transition matrix? NO!!!!!!!! Just because R has no numbers in it that are larger than 1, does NOT mean it has the properties of a transition matrix. One such important property is that the rows of R must all sum to 1. Does that happen?
sum(R,2)
ans =
10.91
8.8577
9.8103
10.163
8.504
9.3237
11.721
11.131
8.2243
8.5949
12.257
8.3164
10.589
11.276
9.1634
9.3135
9.8294
9.5156
10.034
9.174
Now see what happens...
T = R./sum(R,2); % row sums will now be 1.
max(T^20,[],'all')
ans =
0.068219
If you just raise some random matrix to large powers, then you should expect to get garbage results.
Remember that the rows of a Markov transition matrix represent probabilities of a transition to a given state. What do we know about probabilities? They must sum to 1.
  댓글 수: 1
Alexandra Carvalho
Alexandra Carvalho 2020년 1월 9일
Thank you so much. You're absolutely right! I completely forgot about that part and that's why the results weren't what I expected. Thank you again, and sorry for such a rookie question. :)

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

David Hill
David Hill 2020년 1월 7일
You need T.^20 for element-wise
T=T.^20;%you need the dot!
  댓글 수: 1
Alexandra Carvalho
Alexandra Carvalho 2020년 1월 7일
But I don't want to do it element-wise. I'm looking into Markov Chains and the matrix represents transition probabilities. These should never pass the value 1. Also, these probabilities are supposed to stabilize given a large enough n.

댓글을 달려면 로그인하십시오.


Star Strider
Star Strider 2020년 1월 7일
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
Star Strider
Star Strider 2020년 1월 7일
You never mentioned that you are calculateing Markov chain probabilities in your original post.
Alexandra Carvalho
Alexandra Carvalho 2020년 1월 9일
You're right I didn't think it was relevant but turns out my problem was about that and not so much about anything else, I feel so stupid! Sorry once again, have a nice day :)

댓글을 달려면 로그인하십시오.


Christine Tobler
Christine Tobler 2020년 1월 8일
편집: Christine Tobler 2020년 1월 13일
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
David Goodmanson
David Goodmanson 2020년 1월 8일
Hi Christine,
looks like your statement that the sum of each column equals one is not conistent with sum(A,2).
Christine Tobler
Christine Tobler 2020년 1월 13일
Right, I meant to say the sum of each row.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by