Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 1794
Image: ubuntu2004
1
def generator():
2
"""
3
Generates
4
p(t)y'+q(t)y=r(t).
5
One function has no zeros,
6
one function has a unique zero,
7
the last has two zeros.
8
"""
9
t,y = var('t y')
10
order = choice([2,3])
11
if choice([True,False]):
12
yp = var("yp", latex_name="y'")
13
ypp = var("ypp", latex_name="y''")
14
else:
15
yp = var("yp", latex_name="y''")
16
ypp = var("ypp", latex_name="y'''")
17
zeros = [
18
randrange(-6,-3),
19
randrange(-2,3),
20
randrange(5,7)
21
]
22
shuffle(zeros)
23
pqr = [
24
choice([
25
exp(t*randrange(1,6)*choice([-1,1])),
26
t^2+randrange(1,6)^2
27
]),
28
choice([
29
t-zeros[0],
30
# exp(randrange(2,6)*(t-zeros[0]))-1,
31
exp(t)*(t-zeros[0])
32
]),
33
choice([
34
(t-zeros[1])*(t-zeros[2]),
35
]),
36
]
37
constant = randrange(1,6)*choice([-1,1])
38
roll = randrange(1,3)
39
if roll == 0: #dummied out
40
# p has no zeroes, thm says all real numbers
41
p = pqr[0]
42
others = [pqr[1],pqr[2]]
43
shuffle(others)
44
q,r=others
45
t0 = randrange(-6,7)
46
x0 = randrange(-6,7)
47
interval = "(-\\infty,+\\infty)"
48
elif roll == 1:
49
# p has one zero, zeros[0], randomly choose left or right
50
p = pqr[1]
51
others = [pqr[0],pqr[2]]
52
shuffle(others)
53
q,r=others
54
if choice([True,False]):
55
t0 = zeros[0] - randrange(1,5)
56
x0 = zeros[0] + randrange(1,5)
57
interval = f"(-\\infty,{zeros[0]})"
58
else:
59
t0 = zeros[0] + randrange(1,5)
60
x0 = zeros[0] - randrange(1,5)
61
interval = f"({zeros[0]},+\\infty)"
62
else:
63
# p has two zeros, zeros[1] and zeros[2], choose random between them
64
p = pqr[2]
65
others = [pqr[0],pqr[1]]
66
shuffle(others)
67
q,r=others
68
z1 = min([zeros[1],zeros[2]])
69
z2 = max([zeros[1],zeros[2]])
70
t0 = randrange(z1+1,z2)
71
x0 = choice([z1-randrange(1,5),z2+randrange(1,5)])
72
interval = f"({z1},{z2})"
73
ode = shuffled_equation(p*ypp,q*y,r,constant*yp)
74
75
return {
76
"ode": ode,
77
"interval": interval,
78
"t0": t0,
79
"x0": x0,
80
}
81
82