Why matlab giving me same values too many times

1 回表示 (過去 30 日間)
Sam
Sam 2014 年 3 月 15 日
コメント済み: Walter Roberson 2014 年 3 月 16 日
Ok my input function was
r=2;
x(1)=0.3;
N=100
for i=1:N
x(i+1)=r*x(i)*(1-x(i))
end
And, matlab calculated my answer but gave me the same x values for about 6 times. It's very annoying since I don't need the same x values over and over again. Please tell me how can I avoid that? Thanks.
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 3 月 15 日
What are you expecting?
Sam
Sam 2014 年 3 月 15 日
I am expecting to avoid the same values over and over again.

サインインしてコメントする。

採用された回答

Mischa Kim
Mischa Kim 2014 年 3 月 15 日
編集済み: Mischa Kim 2014 年 3 月 15 日
Sumon, I think you are referring to fact that the series approaches x = 0.5 for increasing i. This is absolutely to be expected. For small x the linear term dominates which leads to an increase in x. However, as x is increasing the quadratic term starts to become more prevalent up to a point, where they will balance each other out. This point is "reached" when
x(i) = r*x(i)*(1-x(i))
or, put aside the indices,
x = r*x*(1 - x)
1 = r* (1 - x)
or, solving for x
x = (r - 1)/r = 0.5
At that point, the values for x(i) remain constant, x(i+1) = x(i).
  2 件のコメント
Sam
Sam 2014 年 3 月 15 日
Oh I get it now. Thanks for clearing things up for me.
Walter Roberson
Walter Roberson 2014 年 3 月 16 日
In theory you only get x = 1/2 if your start with x = 1/2 . But in practice when you start with x in the range 0 to 1 exclusive then within a few steps the loss of precision will get you to floating point 0.5 after which it will stay there.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2014 年 3 月 15 日
MATLAB uses finite precision floating point binary numbers. After a few steps of the calculation, all of the answers are the same to within the limited precision. If you require increased precision then you will need to use something like the symbolic toolbox.
x(t) = -1/2*((2/5)^(2^(t-1))-1)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by