Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
20865 views
1
def generator():
2
t = var("t")
3
y,yp = mi_vars("y","y'")
4
t0 = randrange(-2,3)
5
y0 = randrange(-2,3)
6
field_sage,ode = choice([
7
("sin(t+y)",yp==sin(t+y)),
8
("cos(t+y)",yp==cos(t+y)),
9
("y/15-t/3",yp==y/15-t/3),
10
("t/3-y/15",yp==-t/3-y/15),
11
("sin(y/2)",yp==sin(y/2)),
12
("cos(y/2)",yp==cos(y/2)),
13
("t*y/9-t/3",yp==t*y/9-t/3),
14
("t*y/9+t/3",yp==t*y/9+t/3),
15
])
16
othert = t0+choice([-2,2])
17
othery = SR(desolve_rk4(ode.rhs(),y,ivar=t,ics=[t0,y0],end_points=othert,step=0.25)[-1][-1]).n(digits=2)
18
19
return {
20
"field_sage": field_sage,
21
# "slope_field_url": data_url_graphic(plot_slope_field(ode.rhs(), (t,-5,5), (y,-5,5)),file_format="png"),
22
"ode": ode,
23
"y0": y0,
24
"t0": t0,
25
"othert": othert,
26
"othery": othery,
27
}
28
29