Hot answers tagged

5

You may use Piecewise. For your For loop function g[x_] = Piecewise[{#, 1 - # <= x <= 2 + #} & /@ Range[4]] Plot[g[x], {x, -3, 6}] For your example function f[x_] = Piecewise[{ {x , 0 <= x <= 1 - 1/5}, {-x + 2 , 1 + 1/5 <= x <= 2}, {1 - 1/5 , True} }] Plot[f[x], {x, 0, 2}] Hope this helps.


4

If has attribute HoldRest, which you can clear, but I don't recommend that. I think the right solution is to replace a[HoldedArgument] by a[#] &[ToDoBeforeHold], i.e. q[y_] = y; For[i = 1, i <= 4, i++, q[y_] = q[If[1 - i <= x <= 2 + i, #, #2] &[i, y]]]; f[x_] = q[If[7 <= x <= 6, 10 x, x]]; f[x]


1

Here is a community wiki where we can accumulate answers. happy fish {Reverse /@ Flatten @ Outer[f, {1, 2}, {1, 2, 3}]} m_goldberg {Flatten[Table[f[j, i], {i, 2}, {j, 3}]]} J. M. Outer[f[#2, #] &, {1, 2}, {1, 2, 3}]



Only top voted, non community-wiki answers of a minimum length are eligible