Why does Matlab incorrectly return 0 when evaluating an array, but correctly return NaN when evaluating a scalar? -


why expression h(theta) below return 0 , return nan? h(theta) contains division 0 theta = 0 , should return nan. if ask h(0), works fine.

however, when evaluates 0 contained in multi-element array, returns h = 0 when should return nan. if evaluating element zero, returns nan should.

>> theta = [0 1] theta =      0     1 

the first element should nan:

>> h = tan(theta)/(1+(tan(theta)/tan(2.*theta))) h =      0    5.4220  

when evaluating 0 element works correctly:

>> h = tan(theta(1))/(1+(tan(theta(1))/tan(2.*theta(1)))) h =      nan   >> h = tan(theta(2))/(1+(tan(theta(2))/tan(2.*theta(2)))) h =      5.4220 

you need element-wise division ./ instead of / desired result. called right array division.

>> h = tan(theta)./(1+(tan(theta)./tan(2.*theta))) h =        nan    5.4220 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

wso2esb - How to concatenate JSON array values in WSO2 ESB? -