I wanna be able to use the Piecewise function such that I don't have to manually enter all the pieces. For example, say I define


Consider now


I want to be able to do this using some kind of loop inside Piecewise. How can I implement this


1 Answer 1



cond = # < x < # + 1 & /@ Range[0, 2];
f = {x, x^2, x^3};
Plot[Piecewise[Transpose[{f, cond}]], {x, 0, 3}]

enter image description here


Your Answer

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

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