9

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:

$\sqrt{a^2+b^2}$

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

M6299
  • 1,471
  • 1
  • 13
  • 20

3 Answers3

6

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

chyanog
  • 15,542
  • 3
  • 40
  • 78
  • not quite.. if a==0 the max is abs[b]. I suppose because ArcTan doesn't admit the full range of angles. – george2079 Aug 24 '13 at 20:11
  • Thanks for the answer. The ranges of x and ArcTan[t] are different. How come x can be substituted with ArcTan[t]? – M6299 Aug 25 '13 at 05:52
6

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];
Simplify[
    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..?

M6299
  • 1,471
  • 1
  • 13
  • 20
george2079
  • 38,913
  • 1
  • 43
  • 110
5

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] *)
b.gates.you.know.what
  • 20,103
  • 2
  • 43
  • 84