3
$\begingroup$

I have been looking on wolfram reference and here regarding a method to develop solutions for an ODE based on forming an Ansatz and use Mathematica to find the coefficients.

I take the example.

$y''+4y=x^3$

I want to find the unknown coefficients of the Ansatz. We know the ansatz for $y_p$ is $Ax^3+Bx^2+Cx+D$.

So I compute the following:

VL1[y_] := D[y, x, x] + 4 y yp = A1 + B1*x + C1*x^2 + D1*x^3 (*Ansatz*) VL1[yp1] VL1[yp] == x^3 /. {{x -> 1}, {x -> 2}, {x -> 3}, {x -> 0}} sol = Solve[%, {A1, B1, C1, D1}] yp /. sol 

This works well and give the particular solution

$y_p=-\frac{3x}{8} + \frac{x^3}{4}$

However, when I want to develop this into the variation of parameters method for the example:

$y''+4y'-8y=\cos x$

I am stuck. The problem is that the Ansatz is no longer containing variables and coefficients, but unknown functions. The ansatz for this is $y_p=u\cos x+v\sin x$, where $u$ and $v$ are the unknown functions to be found.

Any ideas?

Thanks

$\endgroup$
4
  • 1
    $\begingroup$ You do not use Anstaz with variation of parameters method. Just apply the formula to find $u$ and $v$. There was a question similar to this at This finds the particular solution using variation of parameters may be you could use that function and see if it works? To use variation of parameters you need to first find the basis solutions for the homogeneous solution. $\endgroup$ Commented Sep 13, 2022 at 10:18
  • $\begingroup$ I saw this contribution already, and it is very special and good, your work is excellent. However, I was looking for something simpler, more towards this line of computing as you see here. Is that possible you think? $\endgroup$ Commented Sep 13, 2022 at 10:20
  • $\begingroup$ I think applying these formulas is the most simple way to use variation of parameters. Here is screen shot of the formulas. !Mathematica graphics They are derived using reduction of order method. But you do not need to know that. I just would memorize them just like memorizing the quadratic formula. $\endgroup$ Commented Sep 13, 2022 at 10:24
  • $\begingroup$ Yes, these are the solutions to the variation of parameter method. But how do I plug them in the code above? $\endgroup$ Commented Sep 13, 2022 at 10:29

1 Answer 1

5
$\begingroup$

But how do I plug them in the code above?

I do not know how to explain this in words in comment section other than by showing it. The $y_p$ is found using variation of parameters by applying the formulas (screen shot from math.lamar.edu

enter image description here

The above is implemented in Using the method of undetermined coefficients

Here is how to use the function above

(*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]} ] 

And now call it as follows

odeH = y''[x] + 4*y[x] rhs = x^3; {yh, yp} = hAndp[odeH, rhs, y, x] 

Mathematica graphics

Hence

sol = yh + yp 

Mathematica graphics

Compare to

 DSolve[odeH == rhs, y[x], x] 

Mathematica graphics

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.