Why does matrix power give wrong answer?

I am trying to do a MCMC simulation and need to calculate a small frequency event over a long time. To do this I need to raise
A=[1-1.01E-11,1.01E-11,0;1-3.024E-11,0,3.024E-11;0,0,1];
to a large power (10^10). I am particularly interested in the (1,3) element of the result (the probability of transferring between states 1 and 3 after 10 billion iterations). After 10^9 the (1,3) element is 3.05423999691491e-13. However after 10^10 it is -3.05423999991124e-22. Which is impossible because I am multiplying matrices with strictly non-negative values. As a check I tried (A^(10^9))^10, and this gave a (1,3) entry of 3.05423999966373e-12. Doing the calculation (A^(10^10) using repeated squaring and multiplication) in Excel gave 3.05424E-12.
I am using MATLAB 2013b on windows 7 64-bit.
Why does A^(10^10) fail but (A^(10^9))^10 work?

댓글 수: 1

John D'Errico
John D'Errico 2014년 2월 26일
Time to learn about floating point arithmetic. When your numbers are only held accurately to roughly 16 digits, what do you expect?

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

답변 (1개)

per isakson
per isakson 2014년 2월 27일
편집: per isakson 2014년 2월 27일

0 개 추천

댓글 수: 4

Try
A=[1-1e-12,1e-12,0;1-1e-12,0,1e-12;0,0,1];
B=A^(2^31-1)*A
You get
0.999999999999000 9.99999999999000e-13 2.14748364699785e-15
0.999999999998000 9.99999999998000e-13 1.00214748364600e-12
0 0 1
Now try
B=A^(2^31)
You get
0.999999999999000 9.99999999999000e-13 -9.99999999997652e-25
0.999999999998000 9.99999999998000e-13 9.99999999997652e-13
0 0 1
The answers should be identical. As far as the floating point arithmetic argument, the second calculation can be done with 31 squarings, yet some other algorithm is used and the value in the (1,3) element is horribly wrong. Floating point arithmetic errors alone do not explain the difference in values between A^(2^31-1)*A and A^(2^31).
per isakson
per isakson 2014년 2월 27일
편집: per isakson 2014년 2월 27일
"The answers should be identical." If you think Matlab does not behave as promised, you might want to report it as a bug.

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

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

질문:

2014년 2월 26일

댓글:

2014년 3월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by