zout[:] = [z[1], g - alpha*z[1]**2] return zout # main program starts here T = 10 # end of simulation N = 20 # no of time steps time = np.linspace(0, T, N+1) z0=np.zeros(2) z0[0] = 2.0 ze = euler(f, z0, time) # compute response with constant CD using Euler's method ze2 = euler(f2, z0, time) # compute response with varying CD using Euler's method zh = heun(f, z0, time) # compute response with constant CD using Heun's method zh2 = heun(f2, z0, time) # compute response with varying CD using Heun's method k1 = np.sqrt(g*4*rho_s*d/(3*rho_f*CD)) k2 = np.sqrt(3*rho_f*g*CD/(4*rho_s*d)) v_a = k1*np.tanh(k2*time) # compute response with constant CD using analytical solution # plotting legends=[] line_type=['-',':','.','-.','--'] plot(time, v_a, line_type[0]) legends.append('Analytical (constant CD)') plot(time, ze[:,1], line_type[1])
# main program starts here T = 10 # end of simulation N = 20 # no of time steps time = np.linspace(0, T, N + 1) z0 = np.zeros(2) z0[0] = 2.0 # compute response with constant CD using Euler's method ze = euler(f, z0, time) # compute response with varying CD using Euler's method ze2 = euler(f2, z0, time) # compute response with constant CD using Heun's method zh = heun(f, z0, time) # compute response with varying CD using Heun's method zh2 = heun(f2, z0, time) zrk4 = rk4(f, z0, time) # compute response with constant CD using RK4 zrk4_2 = rk4(f2, z0, time) # compute response with varying CD using RK4 k1 = np.sqrt(g * 4 * rho_s * d / (3 * rho_f * CD)) k2 = np.sqrt(3 * rho_f * g * CD / (4 * rho_s * d)) # compute response with constant CD using analytical solution v_a = k1 * np.tanh(k2 * time) # plotting legends = [] line_type = ['-', ':', '.', '-.', ':', '.', '-.']