1
$\begingroup$

Here I have a Piecewise Function:

f[x_]:=Piecewise[{{53, 0 <= x < 100}, {4, 100 <= x < 102}, {71, 
   102 <= x < 140}, {29, 140 <= x < 184}, {12, 184 <= x < 190}, {8, 
   190 <= x < 191}, {28, 191 <= x < 252}, {72, 252 <= x < 293}, {80, 
   293 <= x < 313}, {15, 313 <= x < 323}, {23, 323 <= x < 355}, {7, 
   355 <= x < 359}, {10, 359 <= x < 364}, {86, 364 <= x < 373}, {38, 
   373 <= x < 459}}]

And I have a Reduce:

Reduce[(f[k] >= 53) && (0 <= k < 1807), k, Integers] // ToString

f[k] is the Piecewise Function above, How to write the code? Thanks~

$\endgroup$
1
  • $\begingroup$ Square brackets are used for function arguments in Mathematica. You were missing a curly bracket in the Piecewise function definition, and also you were not assigning your Piecewise function to any variable. I edited your post to fix this. Could you provide a bit more information please? What do you expect your code to do? I can run it just fine and I get an output from the Reduce[], but I do not know if this is correct or what your problem is. $\endgroup$
    – a20
    Sep 28 at 9:11
2
$\begingroup$

Somewhat improving your code, this can be done as follows.

f[x_] := Piecewise[{{53, 0 <= x < 100}, {4, 100 <= x < 102}, {71, 
102 <= x < 140}, {29, 140 <= x < 184}, {12, 184 <= x < 190}, {8, 
190 <= x < 191}, {28, 191 <= x < 252}, {72, 252 <= x < 293}, {80, 
293 <= x < 313}, {15, 313 <= x < 323}, {23, 323 <= x < 355}, {7, 
355 <= x < 359}, {10, 359 <= x < 364}, {86, 364 <= x < 373}, {38, 
373 <= x < 459}}]
FullSimplify[Reduce[(f[k] >= 53) && (0 <= k < 1807), k, Integers], 
Assumptions -> k \[Element] Integers] // ToString

"0 <= k <= 99 || 101 < k < 140 || 251 < k < 313 || 363 < k < 373"

$\endgroup$
2
  • $\begingroup$ Thanks! It really helps me. $\endgroup$
    – SilvaXiang
    Sep 30 at 11:37
  • $\begingroup$ But if I want to solve the Reduce which involves two or more variables.How can I write the code? Such as: ``` f[x_]=..... g[x_]=... FullSimplify[Reduce[(f[a]=g[b]) && (0< a < 100) && (0<b<200) , a , b, Integer.......]] ``` How can I write this? Could you tell me how to learn writing the code? $\endgroup$
    – SilvaXiang
    Sep 30 at 11:40

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.