我的代码中有这个错误,我想在列表中显示迭代,但是我得到这个错误,有人知道会发生什么,任何建议,谢谢
错误
TypeError Traceback (most recent call last) in () 34 35 if i == 1: ---> 36 print ('{:^15}{:^15.6f}{:^15.6f}{:^15.6f}{:^15.6f}'.format(i-1,Ri,Rs,Rr,F(Rr))) 37 elif i > 1: 38 print ('{:^15}{:^15.6f}{:^15.6f}{:^15.6f}{:^15.6f}{:^15.10f}'.format(i-1,Ri,Rs,Rr,F(Rr),Er)) TypeError: unsupported format string passed to numpy.ndarray.format
代码
from numpy import exp
Ri = 15
Rr = 31/2
Rs = 16
i = 0
Er = 0
Rra = 0
def F(n):
return 745*1-exp(-x/10)-49*(x)
#Funcion para calcular el error relativo
def error (Rra,Rrn):
Erel = abs((Rrn - Rra) / Rrn) * 100
return Erel
print ('{:^15}{:^15}{:^15}{:^15}{:^15}{:^15}'.format('# iter','Ri','Rs','Rr','F(Ri)','Erel(%)'))
while (i < 10):
Er = error(Rra,Rr)
Rra = Rr #Rra sera el Rr anterior para determinar el error relativo
if F(Ri).all() * F(Rr).all() < 0:
Rs = Rr
elif F(Ri).all() * F(Rr).all() > 0:
Ri = Rr
elif F(Rr) == 0:
print('La raiz es',Rr)
Rr = (Ri + Rs) / 2
i = i + 1
#Condicional para el primer error relativo
if i == 1:
print ('{:^15}{:^15.6f}{:^15.6f}{:^15.6f}{:^15.6f}'.format(i-1,Ri,Rs,Rr,F(Rr)))
elif i > 1:
print ('{:^15}{:^15.6f}{:^15.6f}{:^15.6f}{:^15.6f}{:^15.10f}'.format(i-1,Ri,Rs,Rr,F(Rr),Er))
目前没有回答
相关问题 更多 >
编程相关推荐