Azzera filtri
Azzera filtri

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

7 visualizzazioni (ultimi 30 giorni)
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 Commenti
Stephen23
Stephen23 il 7 Gen 2020
Modificato: Stephen23 il 7 Gen 2020
"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 il 7 Gen 2020
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.

Accedi per commentare.

Risposta accettata

John D'Errico
John D'Errico il 7 Gen 2020
Modificato: John D'Errico il 7 Gen 2020
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 Commento
Alexandra Carvalho
Alexandra Carvalho il 9 Gen 2020
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. :)

Accedi per commentare.

Più risposte (3)

David Hill
David Hill il 7 Gen 2020
You need T.^20 for element-wise
T=T.^20;%you need the dot!
  1 Commento
Alexandra Carvalho
Alexandra Carvalho il 7 Gen 2020
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.

Accedi per commentare.


Star Strider
Star Strider il 7 Gen 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 Commenti
Star Strider
Star Strider il 7 Gen 2020
You never mentioned that you are calculateing Markov chain probabilities in your original post.
Alexandra Carvalho
Alexandra Carvalho il 9 Gen 2020
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 :)

Accedi per commentare.


Christine Tobler
Christine Tobler il 8 Gen 2020
Modificato: Christine Tobler il 13 Gen 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 Commenti
David Goodmanson
David Goodmanson il 8 Gen 2020
Hi Christine,
looks like your statement that the sum of each column equals one is not conistent with sum(A,2).

Accedi per commentare.

Categorie

Scopri di più su Descriptive Statistics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by