def plot(x, y, f, title, plt=None): if plt is None: #import matplotlib.pylab as plt import scitools.easyviz as plt plt.figure() plt.plot(x, y, x, f) plt.legend(["approximation", "exact"]) plt.title(title) return plt
def plot(x, y, f, title, plt=None): if plt is None: # import matplotlib.pylab as plt import scitools.easyviz as plt plt.figure() plt.plot(x, y, x, f) plt.legend(["approximation", "exact"]) plt.title(title) return plt
def plotConvergence(cls, scale, error4scale, title, legend, regression = False): p.figure() p.loglog(scale, error4scale, "k-d", xlabel = "samples", ylabel = "error",) # semilogy p.title(title) p.legend(legend) if regression and len(error4scale) > 1: p.hold('on') lineSpace = np.array((scale[0], scale[-1])) slope, intercept, r_value, p_value, std_err = stats.linregress(scale, np.log10(error4scale)) line = np.power(10, slope * lineSpace + intercept) p.plot(lineSpace, line, "k:", legend = "{slope:.2}x + c" \ .format(slope = slope)) p.hardcopy(cls.folder + title + " " + t.strftime('%Y-%m-%d_%H-%M') + ".pdf")
n = 0 while n<N and T[n]>=temp_after_death-0.0001 : T[n+1] = (T[n] - k*dt*((1-theta)*T[n] - T_s))/(1.0 + theta*dt*k) n = n + 1 t = linspace(0,t_end,N+1) return T,t def exact_sol(T0,k,T_s,t_end,dt): N = int(round(t_end/float(dt))) t = linspace(0,t_end,N+1) exact = (T0-T_s)*exp(-t*k) + T_s return exact,t if __name__ == "__main__": T,t = cooling(37.5, 0.1, 14.0, 60.0, 5, 0.5) plot(t,T,"r--o") T_exact,t = exact_sol(37.5, 0.1, 14.0, 60.0, 5) #figure() hold("on") plot(t,T_exact) legend(["discrete sol","exact sol"]) print "maximum error :" ,max(abs(T-T_exact)) raw_input("press enter")