Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
3774 views
ubuntu2004
1
def generator():
2
t = var("t")
3
y,yp,ypp = mi_vars("y","y'","y''")
4
5
# pick a,b for (D-a)(D-b)
6
a = randrange(1,5)*choice([-1,1])
7
b=a
8
while a==b:
9
b = randrange(1,5)*choice([-1,1])
10
# pick particular solution
11
c=a
12
while c in [a,b]:
13
c = choice([2,3,5])
14
d = randrange(1,4)*choice([-1,1])
15
d2 = randrange(1,4)*choice([-1,1])
16
ypart = choice([
17
d*exp(c*t)+d2,
18
d*sin(c*t),
19
d*cos(c*t),
20
])
21
k1 = var("k_1")
22
k2 = var("k_2")
23
ode = shuffled_equation(ypp-(a+b)*yp,a*b*y,-ypart.diff().diff()+(a+b)*ypart.diff()-a*b*ypart)
24
ode_sol = (y==k1*exp(a*t)+k2*exp(b*t)+ypart)
25
26
return {
27
"ode": ode,
28
"ode_sol": ode_sol,
29
}
30