Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Mr Scott's phase plane for Sec. 3.3

Views: 143
Image: ubuntu2004
# declare the variables x, y, t = var('x y t') # declare the system F = [x + 3*y, -2*x - 4*y] # create the vector field # normalize the vector fields so that all of the arrows are the same length # n = sqrt(F[0]^2 + F[1]^2) # plot the vector field # p02 = plot_vector_field((F[0]/n, F[1]/n), (x, -4, 4), (y, -4, 4), aspect_ratio = 1) p02 = plot_vector_field((F[0], F[1]), (x, -4, 4), (y, -4, 4), aspect_ratio = 1) # plot the straightline solutions p02 += plot(-1*x, x, -4, 4, thickness = 2, color = 'red', xmin = -4, xmax = 4, ymin = -4, ymax = 4) p02 += plot(-2/3*x, x, -4, 4, thickness = 2, color = 'red') # solve the system for the initial condition t = 0, x = 2, y = 0 P1 = desolve_system_rk4(F, [x, y], ics=[0, 2, 0], ivar = t, end_points = [-5,5], step = 0.01) # grab the x and y values from the set P1 S1 = [ [j, k] for i, j, k in P1] # plot the solution p02 += line(S1, thickness = 2, axes_labels=['$x(t)$','$y(t)$'], xmin = -4, xmax = 4, ymin = -4, ymax = 4, color = 'blue') # solve the system for the initial condition t = 0, x = -2, y = 0 P2 = desolve_system_rk4(F, [x, y], ics=[0, -2, 0], ivar = t, end_points = [-5,5], step = 0.01) # grab the x and y values from the set P2 S2 = [ [j, k] for i, j, k in P2] # plot the solution p02 += line(S2, thickness = 2, axes_labels=['$x(t)$','$y(t)$'], xmin = -4, xmax = 4, ymin = -4, ymax = 4, color = 'blue') # solve the system for the initial condition t = 0, x = 3, y = -5/2 P3 = desolve_system_rk4(F, [x, y], ics=[0, 3, -5/2], ivar = t, end_points = [-5,5], step = 0.01) # grab the x and y values from the set P2 S3 = [ [j, k] for i, j, k in P3] # plot the solution p02 += line(S3, thickness = 2, axes_labels=['$x(t)$','$y(t)$'], xmin = -4, xmax = 4, ymin = -4, ymax = 4, color = 'green') # display the final plot show(p02) # Save the plot as a pdf to use in LaTeX or Word or your program of choice. p02.save('295_03-03_Notes_Example_02.pdf')