Borrar filtros
Borrar filtros

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 visualización (últimos 30 días)
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.

Respuesta aceptada

Matt J
Matt J el 29 de En. de 2014
Editada: Matt J el 29 de En. de 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 comentarios
Oscar
Oscar el 29 de En. de 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 el 29 de En. de 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;

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by