フィルターのクリア

Looping over Only the Real Positive Roots

1 回表示 (過去 30 日間)
Andrew
Andrew 2012 年 5 月 26 日
In my model, I am searching for a value of one variable, let's call it a, over an interval. To find the best value of this variable, I need to find the five roots of another variable, let's call it b, and search over each of the positive real roots.
When only one of the roots is real, the process is simple. My issue is that I don't know how to only select the positive roots of b and loop through each of those only.
Anyone have any suggestions?
Thanks.

回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 5 月 26 日
RB = roots(b);
PRR = RB( imag(RB) == 0 & real(RB) > 0 );

Andrew
Andrew 2012 年 5 月 27 日
Thank you for the help. Now I have another issue in that sometimes the PRR matrix is empty - no positive real roots. When this happens, I'd like to include an if loop that will set a variable equal to something, but I don't know how to reference the empty set. Any ideas?
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 5 月 27 日
isempty(PRR)

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by