CoCalc Public Files295_03-05_Quiz_09.sagewsOpen with one click!
Author: Randy Scott
Views : 88
Compute Environment: Ubuntu 20.04 (Default)
# declare the variables x, y, t = var('x y t') # declare the system F = [-3*x - 2*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 pQuiz09 = plot_vector_field((F[0]/n, F[1]/n), (x, -4, 4), (y, -4, 4), aspect_ratio = 1) # plot the straightline solutions [-1,1]^T => y = -x pQuiz09 += plot(-1*x, x, -4, 4, thickness = 2, color = 'red', xmin = -4, xmax = 4, ymin = -4, ymax = 4) # 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 pQuiz09 += line(S1, thickness = 2, axes_labels=['$x(t)$','$y(t)$'], xmin = -4, xmax = 4, ymin = -4, ymax = 4, color = 'blue') # display the final plot show(pQuiz09) # Save the plot as a pdf to use in LaTeX or Word or your program of choice. pQuiz09.save('295_03-05_Quiz_09.pdf')