import heat_solver import matplotlib.pyplot as plt import numpy as np from scipy import interpolate ### gamma = 1/6 mesh refinement hinv = 10 kinv = 600 time600 = np.linspace(0,1,num=kinv+1) u_600 = heat_solver.heat_solver(hinv,kinv) gamma = hinv**2./kinv print gamma hinv = 20 kinv = 2400 time2400 = np.linspace(0,1,num=kinv+1) u_2400 = heat_solver.heat_solver(hinv,kinv) gamma = hinv**2./kinv print gamma hinv = 40 kinv = 9600 time9600 = np.linspace(0,1,num=kinv+1) u_9600 = heat_solver.heat_solver(hinv,kinv) gamma = hinv**2./kinv print gamma x = np.linspace(0,1,num=11) x21 = np.linspace(0,1,num = 21) u_24 = interpolate.interp1d(x21,u_2400[1,:]) x41 = np.linspace(0,1,num=41)
import heat_solver import matplotlib.pyplot as plt import numpy as np u1 = heat_solver.heat_solver(10,10) u2 = heat_solver.heat_solver(10,200) u3 = heat_solver.heat_solver(10,600) u4 = heat_solver.heat_solver(10,2000) #u1_arc = heat_solver.heat_solver(10,600, init ='arc') #u_full = heat_solver.heat_solver_full(10,200) x = np.linspace(0,1,num=11) fig1 = plt.figure() ax1 = fig1.add_subplot(111) ax1.plot(x,u1[1,:]) ax1.set_title('u at t=1 with $\lambda =10$') ax1.set_xlabel('x') ax1.set_ylabel('u') plt.savefig('u1.pdf', bbox_inches=0)
import pstats, cProfile import numpy as np import matplotlib.pyplot as plt import pyximport pyximport.install() import heat_solver hinv =10 kinv = 600 x =np.linspace(0,1,num = hinv+1) u_sine = heat_solver.heat_solver(hinv,kinv) u_sine_200 = heat_solver.heat_solver(hinv, 200) u_arc = heat_solver.heat_solver(hinv,kinv, init ='arc') u_arc_200 = heat_solver.heat_solver(hinv,200, init ='arc') fig2 = plt.figure() ax2 = fig2.add_subplot(111) ax2.plot(x,u_sine[1,:], label = 'numerical, $\lambda=1/6$', ls ='--', marker = 'o') ax2.plot(x,heat_solver.exact(x,1), label = 'exact') ax2.plot(x,u_sine_200[1,:], label = 'numerical, $\lambda=1/2$', ls ='--', marker ='x') ax2.set_title('Exact and numerical solutions at t=1 with I.C. $\sin(\pi x)$ ') ax2.set_xlabel('x') ax2.set_ylabel('u') ax2.legend() plt.savefig('u_sine.pdf', bbox_inches=0) fig2 = plt.figure() ax2 = fig2.add_subplot(111) ax2.plot(x,u_arc[1,:], label = 'numerical,$\lambda=1/6$', ls ='--', marker ='o')