Search code examples
minimizemaple

Maple: specify variable over which to maximize


This is a very simple question, but found surprisingly very little about it online...

I want to find the minimizer of a function in maple, I am not sure how to indicate which is the variable of interest? Let us take a very simple case, I want the symbolic minimizer of a quadratic expression in x, with parameters a, b and c.

Without specifying something, it does minimize over all variables, a, b, c and x.

f4 := a+b*x+c*x^2
minimize(f4, location)

I tried to specify the variable in the function, did not work either:

f5 :=(x) ->a+b*x+c*x^2
minimize(f5, location)

How should I do this? And, how would I do if I wanted over two variables, x and y?

fxy := a+b*x+c*x^2 + d*y^2 +e*y

Solution

  • f4 := a+b*x+c*x^2:
    
    extrema(f4, {}, x);
    
                                  /         2\ 
                                  |4 a c - b | 
                                 < ---------- >
                                  |   4 c    | 
                                  \          / 
    
    fxy := a+b*x+c*x^2 + d*y^2 +e*y:
    
    extrema(fxy, {}, {x,y});
    
                           /           2        2\ 
                           |4 a c d - b  d - c e | 
                          < --------------------- >
                           |        4 c d        | 
                           \                     / 
    

    The nature of the extrema will depend upon the values of the parameters. For your first example above (quadratic in x) it will depend on the signum of c.

    The command extrema accepts an optional fourth argument, such as an unassigned name (or an uneval-quoted name) to which is assigns the candidate solution points (as a side-effect of its calculation). Eg,

    restart;
    
    f4 := a+b*x+c*x^2:
    
    extrema(f4, {}, x, 'cand');
    
                                                   2
                                           4 a c - b
                                         {----------}
                                             4 c
    
    cand;
    
                                                 b
                                         {{x = - ---}}
                                                 2 c
    
    fxy := a+b*x+c*x^2 + d*y^2 +e*y:
    
    extrema(fxy, {}, {x,y}, 'cand');
    
                                               2        2
                                    4 a c d - b  d - c e
                                   {---------------------}
                                            4 c d
    
     cand;
    
                                            b          e
                                   {{x = - ---, y = - ---}}
                                           2 c        2 d
    

    Alternatively, you may set up the partial derivatives and solve them manually. Note that for these two examples there is just a one result (for each) returned by solve.

    restart:
    
    f4 := a+b*x+c*x^2:
    
    solve({diff(f4,x)},{x});
    
                                                 b
                                         {x = - ---}
                                                2 c
    
    normal(eval(f4,%));
    
                                                   2
                                          4 a c - b
                                          ----------
                                             4 c
    
    fxy := a+b*x+c*x^2 + d*y^2 +e*y:
    
    solve({diff(fxy,x),diff(fxy,y)},{x,y});
    
                                            b          e
                                    {x = - ---, y = - ---}
                                           2 c        2 d
    
    normal(eval(fxy,%));
    
                                               2        2
                                    4 a c d - b  d - c e
                                    ---------------------
                                            4 c d
    

    The code for the extrema command can be viewed, by issuing the command showstat(extrema). You can see how it accounts for the case of solve returning multiple results.