5
$\begingroup$

I am having trouble figuring out how to find a particular solution to a differential equation using the method of undetermined coefficients. Everything I've found from other sites hasn't worked.

Example equation

y''[x] - 5y'[x] + 6y[x] = xe^x
$\endgroup$
  • $\begingroup$ method of Undetermined Coefficients requires a lookup to match the right hand side with guess particular solution since only limited RHS function will meet this. Only polynomials, trig and exponentials and constants. So hard to program. The first step is really only the hard one to program. Need patterns matching and can be tricky. Use method of variation of parameters. This requires no guess and works easily with computers and can be automated. $\endgroup$ – Nasser Nov 7 '17 at 1:23
9
$\begingroup$

This finds the particular solution using variation of parameters.

(*returns homogeneous and particular solutioins*)
hAndp[odeH_,rhs_,y_,x_]:=Module[{wronskian,u1,u2,solH,y1,y2,leadingC},

  leadingC  = Cases[odeH,c_ y''[x] :>c];
  leadingC  = If[leadingC==={},1,First@leadingC];

  solH      = (y[x]/.First@DSolve[odeH==0,y[x],x]);
  {y1,y2}   = solH/.C[1] y1_ +C[2] y2_:> {y1,y2}; (*basis solutions*)

  wronskian = Det[{{y1,y2},{D[y1,x],D[y2,x]}}];
  u1        = -Integrate[y2 rhs/(leadingC*wronskian),x];
  u2        = Integrate[y1 rhs/(leadingC*wronskian),x];

    {solH, Simplify[y1 u1+y2 u2]}
];

To use like this

Example 1

odeH=y''[x]-5y'[x]+6y[x];
rhs=x Exp[x];
{yh,yp}=hAndp[odeH,rhs,y,x]

Mathematica graphics

fullSolution=yh+yp

Mathematica graphics

Verify

 y[x]/.First@DSolve[odeH==rhs,y[x],x]

Mathematica graphics

Example 2

odeH=3 y''[x]-5y'[x]+6y[x];
rhs=x Sin[x];
{yh,yp}=hAndp[odeH,rhs,y,x]

Mathematica graphics

fullSolution=yh+yp

Mathematica graphics

Verify

 mSolution = Simplify[y[x]/.First@DSolve[odeH==rhs,y[x],x]]

Mathematica graphics

 Simplify[mSolution -fullSolution]

Mathematica graphics

QED

$\endgroup$
  • 2
    $\begingroup$ Style comment: A function that claims to produce "pAndH" -- particular and homogeneous solutions -- in reversed order "{yh,yp}" is likely to lead to much confusion. $\endgroup$ – Eric Towers Nov 7 '17 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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