# Substitute solution into ODE to verify it holds

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?

• see Mathematica documentation page CheckTheResultsOfDSolve Mar 4 at 20:38
• I get True for the last check. Maybe try restarting. Mar 4 at 21:14

## 1 Answer

Using Function:

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

(*True*)