필터 지우기
필터 지우기

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