Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 1794
Image: ubuntu2004
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
x,xp,y,yp = mi_vars("x","x'","y","y'")
11
t = var("t")
12
# nice a-d
13
switch = randrange(3)
14
if switch == 0:
15
a = 3*randrange(-1,2)+randrange(1,3)
16
b = a+choice([-1,1])*3
17
while a*b==4:
18
b = a+choice([-1,1])*3
19
c = choice([1,2,4])*choice([-1,1])
20
d = 4/c
21
elif switch == 1:
22
a = 5*randrange(-1,1)+randrange(1,5)
23
b = a+choice([-1,1])*5
24
while a*b==-4:
25
b = a+choice([-1,1])*5
26
c = choice([1,2,4])*choice([-1,1])
27
d = -4/c
28
elif switch == 2:
29
a = 5*randrange(-1,1)+randrange(1,5)
30
b = a+choice([-1,1])*5
31
while a*b==36:
32
b = a+choice([-1,1])*5
33
c = choice([3,4,6,9,12])*choice([-1,1])
34
d = 36/c
35
x_ode = shuffled_equation(xp,-a*x,-c*y)
36
y_ode = shuffled_equation(yp,-d*x,-b*y)
37
m = (a+b+sqrt((a-b)^2+4*c*d))/2
38
n = (a+b-sqrt((a-b)^2+4*c*d))/2
39
k1 = lcm(m-a,c)/(m-a)*choice([-1,1])
40
k2 = lcm(n-a,c)/(n-a)*choice([-1,1])
41
x_sol = k1*exp(m*t)+k2*exp(n*t)
42
y_sol = (derivative(x_sol)-a*x_sol)/c
43
x0 = x_sol(t=0)
44
y0 = y_sol(t=0)
45
46
return {
47
"x_ode": x_ode,
48
"y_ode": y_ode,
49
"x0": x0,
50
"y0": y0,
51
"x_sol": x_sol,
52
"y_sol": y_sol,
53
}
54
55