フィルターのクリア

Can someone tell me why the E (x) (equation below) work perfect up to E (416)? If I try to calculate the E(x) for any x > 416 the answer that I get is NaN.

1 回表示 (過去 30 日間)
E= @(x)1.2840.*(x<=55)+...
exp(((0.5+((5.9)*((x-55)./(112.3-55)))).^2)./2).*(x>55 & x<=112.3)...
+24.5325.*(x>112.3);
Thanks for the help.

採用された回答

Matt J
Matt J 2014 年 1 月 29 日
編集済み: Matt J 2014 年 1 月 29 日
Because for x>416, the expression
exp(((0.5+((5.9)*((x-55)./(112.3-55)))).^2)./2)
evaluates to Inf due to overflow. Then you multiply this Inf by 0 resulting in NaN. To avoid this, you'll need to use if statements to implement each piece of the function instead of implementing as a sum of the different pieces.
  2 件のコメント
Oscar
Oscar 2014 年 1 月 29 日
Thanks Matt Can you send me a link or example of How to use the if statements to implement each piece of the function?
Matt J
Matt J 2014 年 1 月 29 日
As an alternative to if-statements, you could do this,
function E=Ecalc(x)
E=nan(size(X));
idx=(x<=55);
E(idx)=1.2840;
idx=(x>55 & x<=112.3);
E(idx)=exp(((0.5+((5.9)*((x(idx)-55)./(112.3-55)))).^2)./2);
idx=(x>112.3);
E(idx)=24.5325;

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by