def non_physical_behavior(I, a, T, dt, theta): """ Given lists/arrays a and dt, and numbers I, dt, and theta, make a two-dimensional contour line B=0.5, where B=1>0.5 means oscillatory (unstable) solution, and B=0<0.5 means monotone solution of u'=-au. """ a = np.asarray(a); dt = np.asarray(dt) # must be arrays B = np.zeros((len(a), len(dt))) # results for i in range(len(a)): for j in range(len(dt)): u, t = solver(I, a[i], T, dt[j], theta) # Does u have the right monotone decay properties? correct_qualitative_behavior = True for n in range(1, len(u)): if u[n] > u[n-1]: # Not decaying? correct_qualitative_behavior = False break # Jump out of loop B[i,j] = float(correct_qualitative_behavior) a_, dt_ = st.ndgrid(a, dt) # make mesh of a and dt values st.contour(a_, dt_, B, 1) st.grid('on') st.title('theta=%g' % theta) st.xlabel('a'); st.ylabel('dt') st.savefig('osc_region_theta_%s.png' % theta) st.savefig('osc_region_theta_%s.pdf' % theta)
def non_physical_behavior(I, a, T, dt, theta): """ Given lists/arrays a and dt, and numbers I, dt, and theta, make a two-dimensional contour line B=0.5, where B=1>0.5 means oscillatory (unstable) solution, and B=0<0.5 means monotone solution of u'=-au. """ a = np.asarray(a) dt = np.asarray(dt) # must be arrays B = np.zeros((len(a), len(dt))) # results for i in range(len(a)): for j in range(len(dt)): u, t = solver(I, a[i], T, dt[j], theta) # Does u have the right monotone decay properties? correct_qualitative_behavior = True for n in range(1, len(u)): if u[n] > u[n - 1]: # Not decaying? correct_qualitative_behavior = False break # Jump out of loop B[i, j] = float(correct_qualitative_behavior) a_, dt_ = st.ndgrid(a, dt) # make mesh of a and dt values st.contour(a_, dt_, B, 1) st.grid('on') st.title('theta=%g' % theta) st.xlabel('a') st.ylabel('dt') st.savefig('osc_region_theta_%s.png' % theta) st.savefig('osc_region_theta_%s.eps' % theta)
def amplification_factor(names): # Use SciTools since it adds markers to colored lines from scitools.std import ( plot, title, xlabel, ylabel, hold, savefig, axis, legend, grid, show, figure) figure() curves = {} p = linspace(0, 3, 99) curves['exact'] = A_exact(p) plot(p, curves['exact']) hold('on') name2theta = dict(FE=0, BE=1, CN=0.5) for name in names: curves[name] = A(p, name2theta[name]) plot(p, curves[name]) axis([p[0], p[-1], -20, 20]) #semilogy(p, curves[name]) plot([p[0], p[-1]], [0, 0], '--') # A=0 line title('Amplification factors') grid('on') legend(['exact'] + names, loc='lower left', fancybox=True) xlabel(r'$p=-a\cdot dt$') ylabel('Amplification factor') savefig('A_growth.png'); savefig('A_growth.pdf')
def amplification_factor(names): # Use SciTools since it adds markers to colored lines from scitools.std import (plot, title, xlabel, ylabel, hold, savefig, axis, legend, grid, show, figure) figure() curves = {} p = linspace(0, 3, 99) curves['exact'] = A_exact(p) plot(p, curves['exact']) hold('on') name2theta = dict(FE=0, BE=1, CN=0.5) for name in names: curves[name] = A(p, name2theta[name]) plot(p, curves[name]) axis([p[0], p[-1], -20, 20]) #semilogy(p, curves[name]) plot([p[0], p[-1]], [0, 0], '--') # A=0 line title('Amplification factors') grid('on') legend(['exact'] + names, loc='lower left', fancybox=True) xlabel(r'$p=-a\cdot dt$') ylabel('Amplification factor') savefig('A_growth.png') savefig('A_growth.pdf')