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.

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?

share|improve this question
3  
note it cant even do this: MaxValue[a Sin[x], x, Reals] –  george2079 Aug 26 '13 at 15:53
add comment

3 Answers

up vote 3 down vote accepted

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..?

share|improve this answer
add comment

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] *)
share|improve this answer
    
Would you please explain why a Sin[x] + b Cos[x] is defined as Sqrt[a^2 + b^2] Sin[x + f]. –  M6299 Aug 24 '13 at 10:42
1  
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]. –  b.gatessucks Aug 24 '13 at 11:36
add comment

Try this:

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

gets

enter image description here

Updated

Reduce[{y == a Sin[x] + b Cos[x], a != 0, b != 0}, y, {x}, Reals]
Reduce[%, y, Reals] // LogicalExpand
% // BooleanConvert[#, "CNF"] &

enter image description here

share|improve this answer
    
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 5:52
    
@M6299, Update complete. –  chyaong Aug 25 '13 at 6:32
add comment

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.