[Tutor] script comparing two values - ASCII encoding error
Mic Forster
micforster@yahoo.com
Wed Feb 26 23:21:02 2003
Jeff,
I've seem to have solved the problem:
code with problem:
>>> def f(k, s):
return k / (1-k) * (1-k)**s / (1-(1-k)**s)
>>> j = 1. / 1600
>>> s = 15
>>> def bisect(min, max, delta, function):
fMax = function(max)
fMin = function(min)
assert fMax * fMin < 0
while max - min > delta:
newX = 0.5 * (min + max)
fNew = function(newX)
if fNew * fMax > 0:
max, fMax = newX, fNew
else:
min, fMin = newX, fNew
return newX, fNew
>>> def fun(x):
return f(x, s) – j
UnicodeError: ASCII encoding error: ordinal not in
range(128)
code without problem:
>>> def f(k, s):
return k / (1-k) * (1-k)**s / (1-(1-k)**s)
>>> j = 1. / 1600
>>> s = 15
>>> def bisect(min, max, delta, function):
fMax = function(max)
fMin = function(min)
assert fMax * fMin < 0
while max - min > delta:
newX = 0.5 * (min + max)
fNew = function(newX)
if fNew * fMax > 0:
max, fMax = newX, fNew
else:
min, fMin = newX, fNew
return newX, fNew
>>> def fun(x):
return f(x, s) - j
>>>
For some reason the identation in that last line got
mucked up. Thanks for your help, Mic
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/