1
$\begingroup$

Is there a way to find the minimum of a piecewise functions with parameters?

Here is a simple example:

Minimize[{If[x > 0, 3 x, x^2 - x - 4]}, x] 

works fine, but

Minimize[{If[x > 0, 3 x, x^2 - x - a], -2 < a < 2}, x]

doesn't work at all.

Is there some way to make it work? Or can anyone explain why is not working or suggest other methods to get the minimum?

Edit 1

The answer I would like to get is something like:

If[a < 0, 0, -a]

Edit 2

When I try

Minimize[{If[x > 0, 3 x, x^2 - x - a], -2 < a < 2}, x]

I get as output:

Minimize[{If[x > 0, 3 x, x^2 - x - a], -2 < a < 2}, x] 

I'm using V10.1.0 for Linux x86 (64-bit) (March 24, 2015)"

$\endgroup$
6
  • $\begingroup$ It's not clear to me what you aim at. I would suggest to use Minimize[{If[x > 0, 3 x, x^2 - x - a], -2 < a < 2}, {x, a}] instead. But since Mathematica tells me that there is no minimum, I am in doubt that this is what you are looking for... $\endgroup$ Commented Feb 24, 2018 at 14:43
  • $\begingroup$ It works for me: i.sstatic.net/oMzoE.png -- So does the 2nd one: i.sstatic.net/BBeRX.png $\endgroup$
    – Michael E2
    Commented Feb 24, 2018 at 14:48
  • $\begingroup$ Perhaps you're looking for something like Simplify[Minimize[{If[x > 0, 3 x, x^2 - x - a], 1 < a < 2}, x], 1 < a < 2]? $\endgroup$
    – Michael E2
    Commented Feb 24, 2018 at 14:51
  • $\begingroup$ Thank you Michael, maybe the problem is that i have an older version? I got this : "10.1.0 for Linux x86 (64-bit) (March 24, 2015)" $\endgroup$
    – arsik87
    Commented Feb 24, 2018 at 14:52
  • $\begingroup$ What do you get for output? (It might help to give the output and version details in the question.) I can't try V10.1, but maybe use PiecewiseExpand@If[x > 0, 3 x, x^2 - x - a] for your function. $\endgroup$
    – Michael E2
    Commented Feb 24, 2018 at 14:55

3 Answers 3

2
$\begingroup$

In versions before M11, maybe you can try something like the following:

minimize[{If[pred_, true_, false_], cond_}, x_] := Simplify[
    Min[
        First @ Minimize[{true, pred&&cond},x],
        First @ Minimize[{false, !pred&&cond},x]
    ],
    cond
]

The function needs error checking to be robust, but it works fine for your example (in M10.0):

minimize[{If[x > 0, 3 x, x^2 - x - a], -2 < a < 2}, x]

Min[0, -a]

A more general version that works for Piecewise expressions is also possible.

$\endgroup$
1
  • $\begingroup$ thank you so much! is working !!! :) $\endgroup$
    – arsik87
    Commented Feb 24, 2018 at 16:22
0
$\begingroup$
$Version

(* "10.0 for Mac OS X x86 (64-bit) (December 4, 2014)" *)

Clear[f]

f[x_, a_] = PiecewiseExpand@If[x > 0, 3 x, x^2 - x - a]

(* Piecewise[{{3*x, x > 0}}, -a - x + x^2] *)

Plot3D[f[x, a], {x, -3, 3}, {a, -2, 2}]

enter image description here

Minimize[{f[x, a], -2 < a < 2}, {x, a}]

(* Minimize::wksol: Warning: there is no minimum in the region in which the 
objective function is defined and the constraints are satisfied; returning a 
result on the boundary. >>

{-2, {x -> 0, a -> 2}} *)
$\endgroup$
1
  • $\begingroup$ Thank you so much for the answer! But this is not what I was looking for... I would like to find the minimum as a function of the parameter "a", while, as I understood, in your answer you consider "a" as another variable.. $\endgroup$
    – arsik87
    Commented Feb 24, 2018 at 15:27
0
$\begingroup$

Applying the minimization piecewise gives the expected result

Minimize[{3 x, x > 0}, x] (* {0, {x -> 0}}*)
Minimize[{x^2 - x - a, x <= 0}, x](*{-a, {x -> 0}} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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