Итак, у меня есть единственный интеграл от одной переменной, и я надеюсь сопоставить данные в таблице LaTeX, но я продолжаю получать сообщение об ошибке: 'int': объект не повторяется.
from scipy.integrate import trapz
tvals = [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5] # fixed values of t
xvals = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0] # fixed values of x
xi = np.linspace(0, 1, 100) # xi is the integral variable!
def H(xi, x, t):
series = np.zeros(xi.shape)
for n in range(-300, 300):
series += np.exp(-(x - 2 * n - xi) ** 2 / 4 * t) / np.sqrt(np.pi * t) - np.exp(-(x - 2 * n + xi)**2 / 4 * t)/ np.sqrt(np.pi * t)
return series * 0.5 * np.sin(np.pi * xi)
for t in tvals:
for x in xvals:
TrapzH = trapz(H(xi, x, t), x=None, dx=0.1, axis=-1)
print(TrapzH)
''' We are going to get a lot of values from this given the size of the lists of t and x values. So let us collate the
data into a table and compile the table in LaTeX. '''
from tabulate import tabulate as tbl
for t in tvals:
for x in xvals:
TrapzH = trapz(H(xi, x, t), x=None, dx=0.1, axis=-1)
headers = ["t Values", "x Values", "Output"]
table = [t, x, TrapzH]
print(tbl(table, headers, tablefmt="latex"))
Изменить : Я опубликовал точную ошибку. Код ошибки
Traceback (most recent call last):
File "", line 129, in <module>
print(tbl(table, headers, tablefmt="latex"))
File "", line 1427, in tabulate
tabular_data, headers, showindex=showindex
File "", line 1103, in _normalize_tabular_data
rows = list(map(list, rows))
TypeError: 'int' object is not iterable