Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

When I try to solve the non-homogeneous differential equation

DSolve[ y''[x] + y[x] == a Cos[2x] + b Cos[x] + c Cos[2x-3]+ d Cos[2x]^2-
    6d Cos[2x]+9d + e Cos[x]^2+ fCos[x] Cos[3x]+h Cos[x]^2 Cos[2x-3] +i cos[x]^4, y[x], x] 

I get a solution with squares of $\sin x$ and $\cos x$. I want to remove all the $\sin x$ terms from the solution and want to express the solution in terms of $\cos 2 x$ and $\cos 4x$.

So what should be the input that will give the result that I want?

share|improve this question
    
Note that you have 2 typos: fCos and i cos. If you fix that and Simplify, I think you get what you want (else look at TrigReduce), I hope that helps –  Pinguin Dirk Mar 22 '13 at 17:25
    
Can't I ignore $\sin x$ by Mathematica and express in terms of cos 2x and cos4x? I'm saying this because I have to do lots of maths like this. –  Math.f Mar 22 '13 at 17:32
    
ah sorry misread, I thought you wanted to replace the squares only. –  Pinguin Dirk Mar 22 '13 at 17:38

2 Answers 2

up vote 2 down vote accepted

Borrowing a page from the documentation, the simplest way is to create a ComplexityFunction that makes Sin more expensive, as follows:

solns = DSolve[y''[x] + y[x] == 
          a Cos[2 x] + b Cos[x] + c Cos[2 x - 3] + d Cos[2 x]^2 - 
          6 d Cos[2 x] + 9 d + e Cos[x]^2 + f Cos[x] Cos[3 x] + 
          h Cos[x]^2 Cos[2 x - 3] + i Cos[x]^4, y[x], x];

cfcn[e_] := 100 Count[e, _Sin, {0, Infinity}] + LeafCount[e]
simp = Simplify[ solns, ComplexityFunction -> cfcn ]
(*
{{y[x] -> 
  1/120 (1140 d + 60 e + 45 i + 30 h Cos[3] - 2 h Cos[3 - 4 x] - 
  20 (2 c + h) Cos[3 - 2 x] + 60 b Cos[x] + 120 C[1] Cos[x] - 
  40 a Cos[2 x] + 240 d Cos[2 x] - 20 e Cos[2 x] - 
  20 f Cos[2 x] - 20 i Cos[2 x] - 4 d Cos[4 x] - 4 f Cos[4 x] - 
  i Cos[4 x] + 60 b x Sin[x] + 120 C[2] Sin[x])}}
*)

Note: it can't get rid of all of the Sin terms, but it got rid of most. Also, further tidying up can be done by using Collect:

Collect[ simp, {Sin[_], Cos[_]}]
(*
{{y[x] -> 
  1/120 (1140 d + 60 e + 45 i) + 1/4 h Cos[3] - 
  1/60 h Cos[3 - 4 x] - 1/6 (2 c + h) Cos[3 - 2 x] + 
  1/120 (60 b + 120 C[1]) Cos[x] + 
  1/120 (-40 a + 240 d - 20 e - 20 f - 20 i) Cos[2 x] + 
  1/120 (-4 d - 4 f - i) Cos[4 x] + 
  1/120 (60 b x + 120 C[2]) Sin[x]}}
*)
share|improve this answer

If you really want to remove all Sin[x] terms, you could do the simplification with a substituted variable $a \equiv \cos(x)$, following the general approach in this answer:

solns = DSolve[
   y''[x] + y[x] == 
    a Cos[2 x] + b Cos[x] + c Cos[2 x - 3] + d Cos[2 x]^2 - 
     6 d Cos[2 x] + 9 d + e Cos[x]^2 + f Cos[x] Cos[3 x] + 
     h Cos[x]^2 Cos[2 x - 3] + i Cos[x]^4, y[x], x];

Simplify[solns[[1, 1, 2]] /. x -> ArcCos[a]] /. a -> Cos[x]

eqn

Here, the Cos[x] is restored only after the simplification has already been done on an expression in which a was substituted for Cos[x], thus making Sin[x] more expensive automatically, without the need for a modified ComplexityFunction.

share|improve this answer

Your Answer

 
discard

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

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