Consider the following function:

$a Sin(x)+b Cos(x)$

I tried to obtain the maximum value of this function using MaxValue[]:

MaxValue[a Sin[x] + b Cos[x], x, Reals]

I expect Mathematica to return the following answer:


But Mathematica cannot find the answer. Why does this happen?

  • 3
    $\begingroup$ note it cant even do this: MaxValue[a Sin[x], x, Reals] $\endgroup$
    – george2079
    Aug 26 '13 at 15:53
  • $\begingroup$ @george2079 But I am puzzled, is it a bug or a feature ? $\endgroup$
    – yarchik
    Mar 16 '17 at 20:47

This is essentially what b.g did, except by using Max instead of the second derivative constraint we get the result without rewriting the original expression.

f[x_] = a Sin[x] + b Cos[x];
    Max[f[x] /. Solve[ {f'[x] == 0 }, x] ],
       Assumptions -> {Element[a, Reals], Element[b, Reals], 
         Element[C[1], Integers]}]
Sqrt[a^2 + b^2]

I'm a bit puzzled why the conditional expression on C[1] doesn't simplify out on its own when the C[1] is gone from the expression..?


Try this:

MaxValue[a Sin[x] + b Cos[x] /. x -> 2 ArcTan[t] // TrigExpand, t, Reals]

MaxValue[{y, Reduce[{y == a Sin[x] + b Cos[x], #}, y, {x}, Reals]}, y]& /@
  {Xor[a == 0, b == 0], a!=0 && b!=0} // FullSimplify

enter image description here

  • $\begingroup$ not quite.. if a==0 the max is abs[b]. I suppose because ArcTan doesn't admit the full range of angles. $\endgroup$
    – george2079
    Aug 24 '13 at 20:11
  • $\begingroup$ Thanks for the answer. The ranges of x and ArcTan[t] are different. How come x can be substituted with ArcTan[t]? $\endgroup$
    – M6299
    Aug 25 '13 at 5:52

You can use a more down to earth method :

func = Sqrt[a^2 + b^2] Sin[x + f];
sol = First@Solve[{D[func, {x, 1}] == 0, D[func, {x, 2}] < 0, 
 f \[Element] Reals, a \[Element] Reals, b \[Element] Reals}, x, Reals];

Simplify[func /. sol, Assumptions -> C[1] \[Element] Integers]
(* Sqrt[a^2 + b^2] *)
  • $\begingroup$ Would you please explain why a Sin[x] + b Cos[x] is defined as Sqrt[a^2 + b^2] Sin[x + f]. $\endgroup$
    – M6299
    Aug 24 '13 at 10:42
  • 1
    $\begingroup$ You can do TrigExpand[ Sin[x + f]] and match Cos[f] to a/Sqrt[a^2 + b^2] and Sin[f] to b/Sqrt[a^2 + b^2]. $\endgroup$ Aug 24 '13 at 11:36

Your Answer

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

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