6
$\begingroup$

I am struggling a lot to understand how to do the very basic exercise of substituting a solution into an ODE so see whether the solution is indeed valid. Consider the following ODE:

ode = -pi[x] * pi'[x] - (xi + rn) * pi'[x] - delta * pi[x] + k * x;

My solution is as follows:

a0 = -(((-delta - Sqrt[4 * k + delta^2]) (rn + xi)) / (2 * (delta + 1/2 (-delta - Sqrt[4 * k + delta^2]))));
a1 = 1/2 * (-delta - Sqrt[4 * k + delta^2]);
piSol[x_] := a0 + a1 * x;

I can verify that the solution is correct by manual substitution:

FullSimplify[-(a0 + a1 * x) * (a1) - (xi + rn) * (a1) - delta * (a0 + a1 * x) + k*x] === 0

True

Why does this not work?

FullSimplify[ode /. {pi[x] -> piSol[x], pi'[x] -> D[piSol[x], x]}] === 0

False

What is the correct way to substitute a solution into an ODE to verify that it holds?

$\endgroup$
2
  • 2
    $\begingroup$ see Mathematica documentation page CheckTheResultsOfDSolve $\endgroup$
    – Nasser
    Mar 4 at 20:38
  • 1
    $\begingroup$ I get True for the last check. Maybe try restarting. $\endgroup$
    – Goofy
    Mar 4 at 21:14

1 Answer 1

7
$\begingroup$

Using Function:

FullSimplify[ode /. pi -> Function[x, piSol[x]]] === 0

(*True*)
$\endgroup$

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.