Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: Summer A ODEs
Views: 43
Visibility: Unlisted (only visible to those who know the link)
Image: ubuntu2004
Kernel: SageMath 9.2

Second-order Linear Homogeneous equations

This notebook helps to visualize the solutions to the equation d2ydt2+mdydy+ky=0\frac{d^2y}{dt^2} + m \frac{dy}{dy} + ky = 0 and how they relate to the complex roots of the characteristic polynomial r2+mr+kr^2 + mr + k.

The key thing to notice is how the qualitative behaviour of the system changes depending on where the roots are located in the complex plane in precise way.

@interact def plot_2nd_order_homogeneous(m = slider(vmin = -5, vmax = 5, default = 1, step_size = 0.02, label = "$m$"), k = slider(vmin = -5, vmax = 5, default = 1.5, step_size = 0.02, label = '$k$'), y0 = slider(vmin = -3, vmax = 3, default = 1, step_size = 0.1, label = '$y(0) = $'), yp0 = slider(vmin = -3, vmax = 3, default = 0, step_size = 0.1, label = '$y\'(0) = $'), auto_update = False): t = var('t') roots = [-m/2 + sqrt(m^2 - 4*k)/2, -m/2 - sqrt(m^2 - 4*k)/2] rootsa = [CDF(a).numerical_approx(digits = 3) for a in roots] show("\\text{roots of } r^2 + mr + k \\text{:}\\qquad " + latex(rootsa[0]) + "\\text{ and }" + latex(rootsa[1])) show(point(rootsa[0], size = 20, color = 'red') + point(rootsa[1], size = 20, color = 'red'), figsize = [3,2], xmin = min(-4, -abs(rootsa[0]), -abs(rootsa[1])), xmax = max(3, abs(rootsa[0]), abs(rootsa[1])), ymin = min(-5, -abs(imag(rootsa[0]))), ymax = max(5, abs(imag(rootsa[0]))), title = "Roots") sols = [exp(rootsa[0]*t), exp(rootsa[1]*t)] if rootsa[0] != rootsa[1] else [exp(rootsa[0]*t), t*exp(rootsa[0]*t)] cv1, cv2 = var('cv1,cv2') solve_c = solve([cv1*sols[0](t = 0) + cv2*sols[1](t = 0) == y0, cv1*diff(sols[0], t)( t= 0) + cv2*diff(sols[1], t)( t= 0) == yp0], cv1, cv2, solution_dict = True) c1,c2 = solve_c[0][cv1], solve_c[0][cv2] show(plot(real(c1*sols[0] + c2*sols[1]), (t,0, 8), title = "Solution plot"), ymin = -7, ymax = 7)