Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 189
Image: ubuntu2004
# declare the variables x, y, t = var('x y t') # declare the system F = [2*x - 6*y, 2*x + 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 p030401 = plot_vector_field((F[0]/n, F[1]/n), (x, -4, 4), (y, -4, 4), aspect_ratio = 1) # plot the straightline solutions # p03 += plot(-1/3*x, x, -4, 4, thickness = 2, color = 'red', xmin = -4, xmax = 4, ymin = -4, ymax = 4) # p03 += plot(x, x, -4, 4, thickness = 2, color = 'red') # solve the system for the initial condition t = 0, x = 1, y = 1 P1 = desolve_system_rk4(F, [x, y], ics=[0, 1, 1], 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 p030401 += 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 = -1, y = 1 P2 = desolve_system_rk4(F, [x, y], ics=[0, -1, 1], 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 p030401 += line(S2, thickness = 2, axes_labels=['$x(t)$','$y(t)$'], xmin = -4, xmax = 4, ymin = -4, ymax = 4, color = 'purple') # solve the system for the initial condition t = 0, x = 3, y = 0 P3 = desolve_system_rk4(F, [x, y], ics=[0, 3, 0], ivar = t, end_points = [-5,5], step = 0.01) # grab the x and y values from the set P3 S3 = [ [j, k] for i, j, k in P3] # plot the solution p030401 += 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(p030401) # Save the plot as a pdf to use in LaTeX or Word or your program of choice. p030401.save('295_03-04_Notes_Example_01.pdf')