# How to find the maximum and minimum values of a function

I am given $$\alpha = \sin \theta \cos \phi$$ and $$\beta =\sin \theta \sin \phi$$.

How should I proceed to find the maximum and minimum values for the below function subject to the constraint $$x^2 +y^2 \leq 1$$: $$f(\theta, \phi, x, y) =(\alpha x+\beta y)\left(x^2 +y^2 -2(\alpha x+\beta y)^2\right)$$

Also, what is the point which attains the maxima/minima?

What is the best way to do this?

• Look up Minimize or NMinimize or the equivalent Maximize functions in the documentation. Try to express your functions in MMA code. Try to use those minimizers, then come back with any specific issues you run into. Jan 31 at 15:03
• @MarcoB I tried the following: Maximize[{(ax+by) (y^2 + x^2) -2 (ax^2 + by^2)^2 , x^2 + y^2 <= 1, a=sin(p)cos(q),b=sin(p)sin(q)}, {x, y}] It is saying no global maxima Jan 31 at 15:17
• @wanderer 1) you're missing some spaces in there. It should read a x + b y for example. 2) In Mathematica you use [ ] for function calls, not ( ) so it's not sin(p) but Sin[p]. 3) You should not do the assignment of a,b inside the maximize, and 4) you are not constraining theta or phi and are not maximizing over those at all. Jan 31 at 15:27

f[θ_, ϕ_, x_, y_] := (* here we set u = {α, β} *)

• Also, when i changed the limit from $2\pi$ to $\pi$, I did not get a solution. What I got is this: Minimize[{(x Cos[[Phi]] Sin[[Theta]]+y Sin[[Theta]] Sin[[Phi]]) (x^2+y^2-2 (x Cos[[Phi]] Sin[[Theta]]+y Sin[[Theta]] Sin[[Phi]])^2),0<=[Theta]<=[Pi],0<=[Phi]<=[Pi],x^2+y^2<=1},{[Theta],[Phi],x,y}] Jan 31 at 16:43
• @wanderer yes it's just Abs. Please search the documentation and have a read, as it sounds like you are very new to Mathematica. For the other question, I'm not sure why that happens, but try using the numerical methods NMaximize and NMinimize instead of Minimize/Maximize. Jan 31 at 18:13