Sign up ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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$$

share|cite|improve this question

4 Answers 4

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$

share|cite|improve this answer
+1 A good answer, assuming that understanding was the point of the post. – Ross Millikan Mar 2 '11 at 6:25
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. – 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$$

share|cite|improve this answer
+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. – user17762 Mar 2 '11 at 7:35
@Sivaram: Yes, but once you know it... That is the case with almost every technique I would guess :-) – Aryabhata Mar 2 '11 at 7:36

Read this article:
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

share|cite|improve this answer
Ah, thanks so much! – user6895 Mar 2 '11 at 6:29
Isn't what you gave a solution of $y'' + y = 1 + \tan x$? – Aryabhata Mar 2 '11 at 7:31
@Moron: You are right. Doesn't adding 1 just fix that? – Eric Naslund Mar 2 '11 at 7:38
Yes, but OP might be misled... – Aryabhata Mar 2 '11 at 7:44

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

share|cite|improve this answer
Yeah, but that doesnt really help me learn how to do it... – user6895 Mar 2 '11 at 6:15
@woosh: Technically you did ask for the quickest way to solve the problem..., but I agree that doesn't help with learning! – Eric Naslund Mar 2 '11 at 6:35
@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. – Ross Millikan Mar 2 '11 at 6:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.