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 CenterFile Exchange 中查找有关 Introduction 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