Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Sage examples from in-class

Project: MATH 202
Views: 136
var('x y t') k = 0.08 a = 0.001 r = 0.02 b = 0.00002 prey = k*x - a*x*y - 0.0001*x*x predator = -r*y + b*x*y # The initial conditions are in the form (t, x, y); end_points is the final value of t solution = desolve_system_rk4([prey, predator], [x,y], ics=[0, 1000, 100], ivar = t, end_points = 500) # We need to pick appropriate pairs of points to construct the plots txpoints = [ [i,j] for i, j, k in solution] typoints = [ [i,k] for i, j, k in solution] xypoints = [ [j,k] for i, j, k in solution] # Construct plots separately tx = list_plot(txpoints, plotjoined=true, color='red') ty = list_plot(typoints, plotjoined=true, color='blue') xy = list_plot(xypoints, plotjoined=true, color='green') sf = plot_slope_field((predator)/(prey), (x, 0, 4000), (y, 0, 200), plot_points = 25) # Display the graphs show(tx+ty) show(sf+xy)
(x, y, t)
solve([prey == 0, predator == 0], [x, y])