How to iterate a differential equation in matlab?

6 ビュー (過去 30 日間)
Salman Saeed
Salman Saeed 2015 年 8 月 28 日
コメント済み: Salman Saeed 2015 年 8 月 28 日
I need to iterate a differential equation until the output (the value of p) converges. Here is the code I wrote;
threshold = ((zeros(1,2048)));
old = p;
new = zeros(1,2048);
while norm( old-new) > threshold
old = p;
p = ((p * StateTransitionbwd) - (dd .* p));
new = p;
end
In the equation I am using dp/dt as p. Do you know how should I treat this differential equation and what should I change in my code?
Thanks a lot.

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 8 月 28 日
編集済み: Walter Roberson 2015 年 8 月 28 日
Also note that norm() is non-negative, and you are comparing for > zeros(), so the loop is not going to terminate until the two values are identical in every component, not just close. That is not a good idea: due to numeric roundoff you can get into cycles when you get really really close, alternately overshooting and undershooting, never exactly equal.
Mind you, norm() of a vector is a scalar and you are comparing a scalar to a vector of zeros. That is going to result in a vector of results the same length as the zeros(), with each element identical. The result would be the same as if you were testing against a single 0.
  1 件のコメント
Salman Saeed
Salman Saeed 2015 年 8 月 28 日
I have changed the norm to
while all(abs(old-new) > threshold)
I hope this will be fine as I want all of my elements in vectors to stop when they converge. Moreover please have a look at the link where I have attached a paper.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by