I'm just a beginner learning Mathematica. I'd like to do something with it, but I don't know if it is possible.

Suppose I want to solve a system of differential equations, maybe a nonlinear one, and I just want to check whether or not a certain function satisfies the system. Is it possible to give the ansatz and let Mathematica tell me if I guessed the solution correctly?

Moreover, if there are some parameters, is it possible to know the values of the parameters for which your solution is valid?

If this is possible, can you tell me how to do it or where I should look for (books, pdf or anything) to learn how to do it?


1 Answer 1


No problem (if I understand your question right).

For example the well known ode x''[t]+x[t]==0 is solved by a Sin[t]+b Cos[t]

Check the ansatz

x''[t]+x[t]==0 /. x->Function[{t},a Sin[t]+b Cos[t]]

More general with an additional parameter

x''[t] + x[t] /. x -> Function[{t}, a Sin[c t] + b Cos[c t]]
eq = Coefficient[%, {Sin[c t], Cos[c t]}]
(*{a - a c^2, b - b c^2}*)
Solve[eq == 0, {a, b, c}]
(*{{c -> -1}, {c -> 1}, {a -> 0, b -> 0}}*)
  • $\begingroup$ Yes you understood the question right, thank you very much, it seems it is what I'm looking for. My system is fairly more complicated but one should be able to extend this to my case. I try to do it in the next days, If I don't succeed, should I edit this existing question or ask a new one maybe with a reference to this question? $\endgroup$
    – Erontado
    Commented Oct 8, 2019 at 15:40
  • $\begingroup$ There is only one thing I'm not completely understanding about the answer: does the symbol inline /. means something like assign, or replace? I've seen it somewhere else but I didn't really get it $\endgroup$
    – Erontado
    Commented Oct 8, 2019 at 15:51
  • 1
    $\begingroup$ @AnOrAn: It means to apply the replacement rule that follows. The documentation is found under ReplaceAll. $\endgroup$ Commented Oct 8, 2019 at 15:57
  • 1
    $\begingroup$ @AnOrAn - To find out what the meaning of an object like /. just highlight the object in the notebook and press F1 for help. $\endgroup$
    – Bob Hanlon
    Commented Oct 8, 2019 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.