3
$\begingroup$

I need a solution for t1, t2, flatR, flatC that holds r >= 2*c true for every t.

I want to set up optimization task with a constraint on piecewise inequality that should evaluate to true for every t (for each solution found for target variables - check that it satisfies); but none of the SolveAlways/Satisfiability methods I tried do not work.

c = Piecewise[{{flatC, t1 <= t <= t2}, {0, True}}]; 
r = Piecewise[{{flatR, t1 <= t <= t2}, {0, True}}]; 

cond = And @@ {
     10 <= t1 <= 20, 10 <= t2 <= 20, t1 < t2, (* some basic conds *)
     Assuming[
         Element[t1, Reals] && Element[t2, Reals], 
             Integrate[c, {t, t1, t2}] == 5], (* Integrate = 5 *)
    r >= 2*c (* <-- here I want this to be true for every t *)
};

Minimize[{Assuming[Element[t1, Reals] && Element[t2, Reals], 
    Integrate[r, {t, t1, t2}] + Integrate[c, {t, t1, t2}]], cond}, 
  {t1, t2, flatR, flatC}] (* does not work *)

Seems that I need to somehow express the r >= 2*c as a function, but can't find a way in this setup

Thanks!

Edit:

I removed unnecessary stuff from the problem as suggested in comments:

c = Piecewise[{{flatC, t1 <= t <= t2}, {0, True}}]; 
r = Piecewise[{{flatR, t1 <= t <= t2}, {0, True}}]; 

cond = And @@ {
     (* some basic conds *)
     10 <= t1 <= 20, 10 <= t2 <= 20, t1 < t2, flatC*(t2 - t1) == 5, 

     r >= 2*c (* <-- here I want this to be true for every t *)
};

Minimize[{flatR + flatC, cond}, {t1, t2, flatR, flatC}] (* does not work *)
$\endgroup$
  • $\begingroup$ I recommend using $Assumptions = Element[{t1, t2}, Reals];, then removing the Assuming[] to start with. $\endgroup$ – Feyre Feb 15 '17 at 9:20
  • $\begingroup$ Cleaned up the code a bit to emphasize on the problem $\endgroup$ – grandrew Feb 15 '17 at 10:20
0
$\begingroup$

For all the future guys, here is the answer. It has two parts.


First, to test at each step of NMinimize (that is, not analytical solution) - it is essential to use the ?NumericQ trick http://support.wolfram.com/kb/12502 so the resulting function that will prove that expr holds true for every t would look like:

FlatTrueForAll1[expr_, cc_?NumericQ, rr_?NumericQ, nbb_?NumericQ, 
  tt1_?NumericQ, tt2_?NumericQ] := 
 Boole@TrueQ@
   Reduce[expr /. {flatC -> IntegerPart@cc, flatR -> IntegerPart@rr, 
      flatNB -> IntegerPart@nbb, t1 -> IntegerPart@tt1, 
      t2 -> IntegerPart@tt2}, t, Reals]

so I used it as:

FlatTrueForAll1[r >= 2*c, flatC, flatR, flatNB, t1, t2] == 1

in my constraints.


The second part, is that in general using functions that do symbolic calculations in NMinimize (in my case proving that the expression is true) is slow.

The correct approach to this is to try to solve the original expr for all the variables, before the actual calculation is done:

FlatTrueForAllSolve[expr_] := 
 Assuming[t1 < t < t2, 
  Simplify[Reduce[expr, {flatC, flatR, flatNB, t1, t2}]]]

and use it as:

FlatTrueForAllSolve[r >= 2*c],
$\endgroup$
0
$\begingroup$
c = Piecewise[{{flatC, t1 <= t <= t2}, {0, True}}]
r = Piecewise[{{flatR, t1 <= t <= t2}, {0, True}}]

Using your comment literally:

I actually want to find such a solution that holds r>=2*c true for every t in [t1, t2].

the problem becomes very simple.

For this case c becomes flatC and r becomes flatR.

Further, using the condition

flatC*(t2 - t1) == 5

flatC becomes 5/(t1-t2).

Using these transformations cond becomes

cond = And @@ {10 <= t1 <= t2 <= 20, flatR >= 10/(t2 - t1)}

and minimizing the sum of flatC and flatR becomes

min = Minimize[{flatR + 5/(t2 - t1), cond}, {t1, t2, flatR}]

(* {3/2, {t1 -> 10, t2 -> 20, flatR -> 1}} *)
$\endgroup$
  • $\begingroup$ Thank you for your reply! I actually want to find such a solution that holds r>=2*c true for every t in [t1, t2]. Having a general solution over t and as a function of flatC does not help, and I need the exact numbers here. The problem statement that I initially posted is not defined correctly in this regard and is not to be solved as-is, despite the correct syntax. $\endgroup$ – grandrew Feb 16 '17 at 12:36
  • $\begingroup$ @grandrew Ok. I have updated according to your latest comment. There is only one solution that fills all the criteria stipulated. $\endgroup$ – Jack LaVigne Feb 18 '17 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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