# Creating random differential equations

I'm working on an educational project and new to Mathematica Language. Can I create,like multivariance equations with different f[x] in y'[x]=f[x] by using one function? The output should be like this:

I have problems with realization so any help is good. Thanks in advance.

a1 = RandomInteger[Range[-1, 1]];
a2 = RandomInteger[Range[-1, 1]];
a3 = RandomInteger[Range[-1, 1]];
d = RandomChoice[Range[1, 3]];
randtri = RandomChoice[{Sin, Cos, Exp}];

eqn := {y'[t] == RandomChoice[Range[5]] y[t] + a1*randtri[t] + a2*y[t]*randtri[t] + a3*Power[y[t], d]}


Does this answer part of what you are looking for?

We can use RandomChoice to select different components of a differential equation. (Other Random functions could also be suitable)

eqn := {y'[t] == RandomChoice[Range[7]] y[t] + RandomChoice[{Sin, Cos, Exp}][t],
y[0] == RandomChoice[Range[4]]}


Every time eqn is evaluated, we get a different equation

eqn
(* {Derivative[1][y][t] == Cos[t] + 6 y[t], y[0] == 2} *)


which we can solve

DSolve[%, y[t], t]
(* {{y[t] -> 1/37 (80 E^(6 t) - 6 Cos[t] + Sin[t])}} *)


Extending this to multiple variables is not too hard.

• Thanks,thats's it! I suppose, after that can use TraditionalForm function to get the output like on image I posted earlier? Commented Jun 4, 2021 at 21:18
• TraditionalForm will give a (different) conventional mathematical representation of the equation, in terms of y'(t), rather than dy/dt, but presumably suitable for generating problem sheets. Commented Jun 4, 2021 at 22:48
• got it, but now I have only blank graphs like here: ibb.co/64YjMwv Commented Jun 4, 2021 at 23:28
• Your solution has an undefined constant C1. Your equation needs to specify boundary conditions Commented Jun 5, 2021 at 5:27
• So DSolve function has to get additional parameters, added y[0] == -1 in {} branches and got the graph. Commented Jun 5, 2021 at 8:01