This appeared on my professor's test review, and its taken me hours to, surprise surprise, get the wrong answer. Could someone help me with the method I should be using to solve this?

$$y^{\prime\prime}+y=\tan x$$


The quick rigorous method I can think of is by variation of parameters.

The solution is given by $y = y_h + y_p$ where $y_h$ is the homogeneous part of the solution and $y_p$ is the particular solution.

The solution to the homogeneous part is $y_h(x) = c_1 \cos(x) + c_2 \sin(x)$.

$y_p$ is obtained by variation of parameters as follows:

The reason for writing it as a linear combination of $\cos(x)$ and $\sin(x)$ is that these two are the linearly independent solution to the homogeneous part.

$$y_p = a(x) \cos(x) + b(x) \sin(x)$$ $y_p' = a'(x) \cos(x) + b'(x) \sin(x) - a(x) \sin(x) + b(x) \cos(x)$.

Set $a'(x) \cos(x) + b'(x) \sin(x) = 0$ and hence $y_p' = - a(x) \sin(x) + b(x) \cos(x)$.

$y_p'' = - a'(x) \sin(x) + b'(x) \cos(x) - a(x) \cos(x) -b(x) \sin(x) = b'(x) \cos(x) - a'(x) \sin(x) - y_p$

Hence, we have $a'(x) \cos(x) + b'(x) \sin(x) = 0$ and $- a'(x) \sin(x) + b'(x) \cos(x) = \tan(x)$.

Solve for $a(x)$ and $b(x)$ from the two equations to get $b'(x) = \sin(x)$ and $a'(x) = -\frac{\sin^2(x)}{\cos(x)}$.

From which we get $b(x) = -\cos(x)$ and $a(x) = \sin(x) + \log \left( \left| \frac{\cos(x/2) - \sin(x/2)}{\cos(x/2) + \sin(x/2)} \right| \right)$

and plug it back in and simplify to get the particular solution as

$$y_p = \cos(x) \log \left( \left| \frac{\cos(x/2) - \sin(x/2)}{\cos(x/2) + \sin(x/2)} \right| \right)$$

The final solution is

$$y = c_1 \cos(x) + c_2 \sin(x) + \cos(x) \log \left( \left| \frac{\cos(x/2) - \sin(x/2)}{\cos(x/2) + \sin(x/2)} \right| \right)$$

EDIT: Taking a cue from Aryabhata's post, the Green's function for this equation (which is nothing but a 1D Helmholtz equation with unit wavenumber) is $G(x) = -i \frac{e^{i|x|}}{2}$ and hence the particular solution is $\int G(x-y) \tan(y) dy$

  • 2
    $\begingroup$ +1 A good answer, assuming that understanding was the point of the post. $\endgroup$ – Ross Millikan Mar 2 '11 at 6:25
  • 1
    $\begingroup$ Yep, I was able to find a'(x)=-sin(x)tan(x) and b'(x)=sin(x) and integrating for those gave me the right answer. $\endgroup$ – user6895 Mar 2 '11 at 6:32

The method below will solve equations of the form:

$$y'' + y = \frac{f'(x)}{\cos x}$$

First notice that $\displaystyle (h \cos x)'' = h'' \cos x - 2 h' \sin x - h \cos x$

Thus if $\displaystyle y = h \cos x$, then $\displaystyle y'' + y = h'' \cos x - 2h' \sin x$

Thus $\displaystyle (y'' + y')\cos x = h'' \cos^2 x - 2h' \sin x \cos x = (h' \cos^2 x)'$

Thus we get $$h' \cos^2 x = f(x) + A$$

And so

$$y = \cos x \int (f(x) + A)\sec^2 x \ \text{d}x$$

In your case, $\displaystyle f(x) = - \cos x$ and so

$$y = \cos x \ \int (A - \cos x) \sec^2 x \ \text{d}x = A\sin x - \cos x \ \log (\sec x + \tan x) + B \cos x$$

  • $\begingroup$ +1. Though I doubt if it is possible to come up with this idea in an timed test :). And this method should solve any right hand side i.e. $y'' + y = g$ then $y = \cos(x) \int ((\int g(y) \cos(y)dy) +A ) \sec^2(x) dx$ which is nothing but a Green's function sort of approach to solve the equation. $\endgroup$ – user17762 Mar 2 '11 at 7:35
  • $\begingroup$ @Sivaram: Yes, but once you know it... That is the case with almost every technique I would guess :-) $\endgroup$ – Aryabhata Mar 2 '11 at 7:36

Read this article: http://www.sosmath.com/diffeq/second/variation/variation.html
It talks about "Variation of Parameters" which is what you need to use to solve it. A solution ends up being: $$y=-\cos(x)\ln\left(\sec(x)+\tan(x)\right).$$

All of this is covered in detail in the link. Also see http://en.wikipedia.org/wiki/Variation_of_parameters


If you feed d^2y/dx^2+y=tan(x) to Wolfram Alpha you get a solution.

  • 3
    $\begingroup$ Yeah, but that doesnt really help me learn how to do it... $\endgroup$ – user6895 Mar 2 '11 at 6:15
  • 4
    $\begingroup$ @woosh: Technically you did ask for the quickest way to solve the problem..., but I agree that doesn't help with learning! $\endgroup$ – Eric Naslund Mar 2 '11 at 6:35
  • 1
    $\begingroup$ @Eric: @woosh: I have a tendency to be very literal (or to take the cheap solution) But there are many ways to solve a problem. I hit the other answers with an upvote. $\endgroup$ – Ross Millikan Mar 2 '11 at 6:43

Your Answer

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