Sorry I missed a line when transcribing the code snippet in my message.
The while loop should read:
while true
k = (i + j) / 2
if h < htab[k]
j = k
else
i = k
end
if j <= i+1
break
end
end
On Saturday, May 17, 2014 7:46:40 PM UTC-7, Jameson wrote:
>
> Where did you define k? I don't see it in you code snippet. It seems
> likely that it isn't an integer, given the error
>
> On Saturday, May 17, 2014, <[email protected] <javascript:>> wrote:
>
>> I'm trying to understand why I'm getting an InexactError() in the
>> following bit of code:
>>
>> NTAB = 8
>>
>> htab = [3280.84 * x for x in (0.0, 11.0, 20.0, 32.0, 47.0, 51.0, 71.0,
>> 84.852)]
>>
>> ttab = [1.8 * x for x in (288.15, 216.65, 216.65, 228.65, 270.65, 270.65,
>>
>> 214.65, 189.946)]
>>
>> ptab = [2116.21662 * x for x in (1.0, 2.233611e-1, 5.403295e-2,
>> 8.5666784e-3,
>>
>> 1.0945601e-3, 6.6063531e-4,
>> 3.9046834e-5, 3.68501e-6)]
>>
>> gtab = fill(0.0, NTAB)
>>
>> for i = 1:NTAB-1
>>
>> gtab[i] = ((ttab[i+1] - ttab[i]) / (htab[i+1] - htab[i]))
>>
>> end
>>
>> gtab[NTAB] = 0.0
>>
>> function atmosphere(alt::Float64)
>>
>> h::Float64 = alt * REARTH / (alt + REARTH) # convert geometric
>> to
>>
>> # geopotential altitude
>> i = 1
>> j = NTAB
>>
>> while true
>>
>
>> if h < htab[k]
>> j = k
>> else
>> i = k
>> end
>>
>> if j <= i+1
>>
>> break
>>
>> end
>>
>> end
>>
>> end
>>
>>
>>
>> At the line where I'm making the comparison with h < htab[k], I get an
>> InexactError() when any value is passed into the function, but I'm not sure
>> what the reason is as I'm still beginning with Julia. If anyone would be
>> kind enough to point out my mistake, then I would appreciate it.
>>
>> Thanks!
>>
>