import numpy as np
import matplotlib.pyplot as plt
nterms = 100
nrs = 100
r = np.linspace(0, 1, nrs).reshape(-1, 1)
tvec = np.array([0.0001, 0.001, 0.01, 0.1, 0.5])
Temp = np.zeros((nrs, len(tvec)))
sign = 1
for n in range(1, nterms + 1):
term = sign * np.sin(n * np.pi * r) / (n * np.pi * r) * np.exp(-(n * np.pi)**2 * tvec)
if r[0] == 0:
term[0, :] = sign * np.exp(-(n * np.pi)**2 * tvec)
Temp += term
sign = -sign
Temp = 1 - 2 * Temp
plt.figure()
plt.plot(r, Temp)
plt.show(block=False)
output = np.column_stack( (r, Temp) )
with open("transsph.dat", "w") as f:
np.savetxt(f, output, fmt='%f', header="output")