Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
20865 views
1
def generator():
2
'''
3
Produces systems of the form
4
(D-a)x+(-c)y=0
5
(-d)x+(D-b)y=0
6
for nice values of a,b,c,d; namely, resulting in general solutions
7
k_1e^(mt)+k_2e^(nt)
8
for integers m,n
9
'''
10
11
def cardinal(dxdt,dydt,x,y):
12
if dydt(x=x,y=y)>0:
13
direction = "north"
14
elif dydt(x=x,y=y)<0:
15
direction = "south"
16
if dxdt(x=x,y=y)>0:
17
direction += "east"
18
elif dxdt(x=x,y=y)<0:
19
direction += "west"
20
return direction
21
22
23
x_int = randrange(-5,6)
24
y_int = randrange(-5,6)
25
dxdt_rise_sign = choice([-1,1])
26
dxdt_rise = dxdt_rise_sign*randrange(1,6)
27
dxdt_run = randrange(1,6)
28
dydt_rise = -dxdt_rise_sign*randrange(1,6)
29
dydt_run = randrange(1,6)
30
x = var("x")
31
y = var("y")
32
dxdt = dxdt_rise*(x-x_int)-dxdt_run*(y-y_int)
33
if dxdt_rise_sign>0:
34
dxdt_slope = "positive"
35
dydt_slope = "negative"
36
else:
37
dydt_slope = "positive"
38
dxdt_slope = "negative"
39
dydt = choice([-1,1])*(dydt_rise*(x-x_int)-dydt_run*(y-y_int))
40
if choice([True,False]):
41
dxdt,dydt = dydt,dxdt
42
dxdt_slope,dydt_slope = dydt_slope,dxdt_slope
43
top_arrows = cardinal(dxdt,dydt,x_int,y_int+1)
44
bottom_arrows = cardinal(dxdt,dydt,x_int,y_int-1)
45
right_arrows = cardinal(dxdt,dydt,x_int+1,y_int)
46
left_arrows = cardinal(dxdt,dydt,x_int-1,y_int)
47
48
return {
49
"dxdt": dxdt.expand(),
50
"dydt": dydt.expand(),
51
"intersection": (x_int,y_int),
52
"dxdt_slope": dxdt_slope,
53
"dydt_slope": dydt_slope,
54
"top_arrows": top_arrows,
55
"bottom_arrows": bottom_arrows,
56
"right_arrows": right_arrows,
57
"left_arrows": left_arrows,
58
}
59