if condition for infinity

19 ビュー (過去 30 日間)
SITI AISHAH
SITI AISHAH 2019 年 4 月 19 日
コメント済み: madhan ravi 2019 年 4 月 20 日
Please help me regarding this;
slenderness = input ('what is your l/d?')
if slenderness == 1
Sommerfeld = input ('Please enter your Sommerfeld Number')
interp1 (Somm_Num,Flow_Variable_1,Sommerfeld)
elseif slenderness == 1/2
Sommerfeld = input ('Please enter your Sommerfeld Number')
interp1 (Somm_Num,Flow_Variable_2,Sommerfeld)
elseif slenderness == 1/4
Sommerfeld = input ('Please enter your Sommerfeld Number')
interp1 (Somm_Num,Flow_Variable_3,Sommerfeld)
elseif slenderness == infinity
Sommerfeld = input ('Please enter your Sommerfeld Number')
interp1 (Somm_Num,Flow_Variable_4,Sommerfeld)
end
my slenderness is infinity, but when i enter that,it says 'error using input'

回答 (1 件)

John D'Errico
John D'Errico 2019 年 4 月 19 日
編集済み: John D'Errico 2019 年 4 月 19 日
You cannot test for the word 'finite', and expect it to return a valid result, when compared to an inf value.
x = inf
x =
Inf
>> x == 'finite'
ans =
1×6 logical array
0 0 0 0 0 0
>> x == inf
ans =
logical
1
>> isinf(x)
ans =
logical
1
However, you can use the function isinf, which will return true for either -inf or +inf.
Personally, I would STRONGLY suggest that you learn to use and write functions, instead of relying on tools like input in the first place.
  2 件のコメント
SITI AISHAH
SITI AISHAH 2019 年 4 月 20 日
I have test for infinity before, then I try the word'finite' since it says error using input. Instead of the word infinity, what should I write to represent for infinity value ?
madhan ravi
madhan ravi 2019 年 4 月 20 日
SITI AISHAH answer moved here:
It's simple! I have tried replace the word 'infinity' with Inf, and the script is running without any error. yeszza!!!

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

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by