Clear Filters
Clear Filters

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 view (last 30 days)
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.

Accepted Answer

Matt J
Matt J on 29 Jan 2014
Edited: Matt J on 29 Jan 2014
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 Comments
Oscar
Oscar on 29 Jan 2014
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 on 29 Jan 2014
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;

Sign in to comment.

More Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!