Why does the expression for h(theta) below sometimes return 0 and sometimes return NaN? h(theta) contains a division by zero for theta = 0 and should always return NaN. If I just ask for h(0), it all works fine.
However, when it evaluates a zero contained in a multi-element array, it returns h = 0 when it should return NaN. But if specifically evaluating only the element that is zero, then it returns NaN as it should.
>> theta = [0 1]
theta =
0 1
The first element should be NaN:
>> h = tan(theta)/(1+(tan(theta)/tan(2.*theta)))
h =
0 5.4220
When evaluating the zero element specifically it 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
>>to the input lines for formatting and better readability.