Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 1794
Image: ubuntu2004
1
def generator():
2
t = var("t")
3
y,yp,ypp = mi_vars("y","y'","y''")
4
5
roll = randrange(3)
6
if roll==0:
7
# pick n for y=kx^n
8
n = randrange(2,4)*choice([-1,1])
9
# pick initial value
10
t0 = randrange(1,5)*choice([-1,1])
11
# pick coefficient
12
k = randrange(1,5)*choice([-1,1])
13
ode = shuffled_equation(t*yp,-n*y)*choice([2,3])
14
ivp_sol = (y == k*t^n)
15
y0 = k*t0^n
16
elif roll==1:
17
# pick p(t) for y=e^p(t)
18
p = choice([
19
randrange(1,4)*choice([-1,1])*
20
t^2+randrange(-3,4)*t+randrange(-5,6),
21
randrange(1,4)*choice([-1,1])*cos(t),
22
randrange(1,4)*choice([-1,1])*sin(t)
23
])
24
# pick coefficient
25
k = randrange(1,5)*choice([-1,1])
26
ode = shuffled_equation(yp,-p.diff()*y)*choice([2,3])
27
ivp_sol = (y==k*exp(p))
28
t0=0
29
y0 = k*exp(p(t=t0))
30
else:
31
# solves to y^n=(t poly)
32
y0 = randrange(2,5)
33
n = randrange(2,4)
34
t0 = randrange(2,4)*choice([-1,1])
35
first_coeff = randrange(1,4)
36
second_coeff = randrange(1,4)
37
constant = y0^n-first_coeff*t0^2-second_coeff*t0
38
ode = shuffled_equation(-n*yp*y^(n-1),2*first_coeff*t,second_coeff)*randrange(2,4)/y^randrange(1,n)
39
ode = ode.expand()
40
ivp_sol = (y==(first_coeff*t^2+second_coeff*t+constant)^(1/n))
41
42
return {
43
"ode": ode,
44
"t0": t0,
45
"y0": y0,
46
"ivp_sol": ivp_sol,
47
}
48
49