Why h(theta)does the expression for below sometimes return 0and sometimes return NaN? h(theta)contains division by zero for theta = 0and should always return NaN. If I just ask h(0), everything will work well.
However, when it calculates the zero contained in a multi-element array, it returns h = 0when it should return NaN. But if you specifically evaluate only an element that is zero, it returns NaN, as it should be.
>> 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 a null element, 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
source
share