# Variation of Parameters

Variation of parameters, like the method of undetermined coefficients, is another method for finding the particular solution of an nth-order linear differential equation `L(y)=phi(x)` once the solution to the associated homogeneous equation `L(y) = 0` is known.

Recall from the linear independence note that if `y_1(x),\ y_2(x),\ ...,\ y_n(x)` are `n` linearly independent solutions of `L(y)=0`, the general solution of `L(y)=0` is `y_h=c_1 y_1(x)+c_2 y_2(x)+...+c_n y_n(x)`.

The variation of parameters method assumes that the particular solution has the form of the homogeneous solution, except that the constants `c_i` (`i=1, 2, ..., n`) are functions of `x` (that's why it is called variation of parameters): `y_p=c_1(x) y_1(x)+c_2(x)y_2(x)+...+c_n(x)y_n(x)`.

We know `y_i(x)` (`i=1, 2, ..., n`), but we need to determine `c_i(x)` (`i=1, 2, ..., n`).

For this, set up the following linear system of equations:

`{(c_1'y_1+c_2'y_2+...+c_n'y_n=0),(c_1'y_1'+c_2'y_2'+...+c_n'y_n'=0),(...),(c_1'y_1^((n-1))+c_2'y_2^((n-1))+...+c_n'y_n^((n-1))=0),(c_1'y_1^((n))+c_2'y_2^((n))+...+c_n'y_n^((n))=0):}`

Then, integrate each `c_i'` to obtain `c_i`, disregarding all constants of integration. This is permissible because we are seeking only one particular solution.

Since `y_1(x),\ y_2(x),\ ...,\ y_n(x)` are `n` linearly independent solutions of the same equation `L(y) = 0`, their Wronskian is not zero. This means that the system has a nonzero determinant and can be solved uniquely for `c_1'(x),\ c_2'(x),\ ...,\ c_n'(x)`.

The method of variation of parameters can be applied to all linear differential equations. It is therefore more powerful than the method of undetermined coefficients, which is restricted to linear differential equations with constant coefficients and particular forms of `phi(x)`. Nonetheless, in those cases where both methods are applicable, the method of undetermined coefficients is usually the more efficient and, hence, the preferable one.

As a practical matter, the integration of `v_i'(x)` may be impossible to perform. In any such case, other methods (in particular, numerical techniques) should be employed.

**Example 1.** Solve `y''-2y'+y=(e^x)/x`.

The homogeneous solution is `y_h=c_1e^(x)+c_2xe^x`.

To find the particular solution, set up the system:

`{(c_1'e^x+c_2'xe^x=0),(c_1'(e^x)'+c_2'(xe^x)'=(e^x)/x):}`

Or

`{(c_1'e^x+c_2'xe^x=0),(c_1'e^x+c_2'(xe^x+e^x)=(e^x)/x):}`

Subtract the first equation from the second: `c_2'e^x=(e^x)/x`, or `c_2'=1/x`.

From the first equation, `c_1'=-c_2'x=-1/x x=-1`.

So, `c_2=int 1/x dx=ln(|x|)`, and `c_1=int -1dx=-x`.

Thus, `y_p=c_1e^x+c^2xe^x=-xe^x+ln(|x|)xe^x`.

Finally, the general solution is `y=y_h+y_p=c_1e^x+c_2xe^x-xe^x+ln(|x|)xe^x=c_1e^x+c_3xe^x+ln(|x|)xe^x`, where `c_3=c_2-1`.

Let's work one more example.

**Example 2.** Solve `2y''-3y'+y=e^x`.

The corresponding homogeneous equation is `2y''-3y'+y=0`. The characteristic equation is `2r^2-3r+1=0` that has the roots `r_1=1, r_2=1/2`.

So, `y_h=c_1e^x+c_2e^(1/2 x)`.

Now, be careful when applying the variation of parameters method. To apply it correctly, the coefficient near the highest derivative has to be 1; so, first divide both sides of the differential equation by `2`: `y''-1.5y'+0.5y=1/2 e^x`.

Now, set up the system:

`{(c_1'e^x+c_2'e^(1/2 x)=0),(c_1'(e^x)'+c_2'(e^(1/2 x))'=1/2 e^x):}`

Or

`{(c_1'e^x+c_2'e^(1/2 x)=0),(c_1'e^x+1/2 c_2'e^(1/2 x)=1/2 e^x):}`

Subtract the first equation from the second: `-1/2c_2'e^(1/2 x)=1/2e^x` or `c_2=-e^(1/2 x)`.

From the first equation, `c_1'=-c_2'e^(-1/2x)=-(-e^(1/2 x))e^(-1/2 x)=1`.

So, `c_1=int 1dx=x`, and `c_2=int -e^(1/2 x)dx=-2e^(1/2 x)`.

Therefore, `y_p=c_1e^x+c_2e^(1/2 x)=xe^x-2e^x`.

Finally, `y=y_h+y_p=c_1e^x+c_2e^(1/2 x)+xe^x-2e^x=c_3e^x+c_2e^(1/2 x)+xe^x`, where `c_3=c_1-2`.

Now, let's consider one final example.

**Example 3.** Find the general solution of `y'''+y'=1/(cos(x))`.

The solution of the corresponding homogeneous equation is `y_h=c_1+c_2cos(x)+c_3sin(x)`.

To find the particular solution, set up the system:

`{(c_1'*1+c_2'cos(x)+c_3'sin(x)=0),(c_1'*(1)'+c_2'(cos(x))'+c_3'(sin(x))'=0),(c_1'*(1)''+c_2'(cos(x))''+c_3'(sin(x))''=1/(cos(x))):}`

Or

`{(c_1'+c_2'cos(x)+c_3'sin(x)=0),(-c_2'sin(x)+c_3'cos(x)=0),(-c_2'cos(x)-c_3'sin(x)=1/(cos(x))):}`

Solving this system gives `c_1'=1/(cos(x)),\ c_2'=-1,\ c_3'=-tan(x)`.

So,

`c_1=int 1/(cos(x))dx=ln(|(1+sin(x))/(cos(x))|)`

`c_2=int -1dx=-x`

`c_3=int -tan(x)dx=ln(|cos(x)|)`.

Thus, `y_p=c_1+c_2cos(x)+c_3sin(x)=ln(|(1+sin(x))/(cos(x))|)-xcos(x)+ln(|cos(x)|)sin(x)`.

Finally, the general solution is

`y=y_h+y_p=c_1+c_2cos(x)+c_3sin(x)+ln(|(1+sin(x))/(cos(x))|)-xcos(x)+ln(|cos(x)|)sin(x)`