Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm currently working with piecewise functions and I'm trying to find an easy way to define and plot them using a short and straightforward piece of code. I use escpwesc to type the piecewise function in the same manner I'd do it on paper, and I used to put \\InputFormatat the end to obtain a line of code that I can use to define a new function. This method has worked for me, until I tried to use x[t_]:=InputForm[pwF]where pwF is the piecewise function typed using the escpwesc method. By doing this, I can evaluate the new function x[t] manually; for example, if I evaluate x[0.1] I will get 1, or if I evaluate x[-1] I will get -1. However, when I try to plot the function using


I get an empty frame.

share|improve this question
Excuse me, I am new in stack exchange, what do you mean by "post complete MWE"? I may have taken Mathematica's description of InputForm too literally, as for expr it says it "prints as a version of expr suitable for input to Mathematica". That's why I thought it could be a valid definition. –  Daniel Fernando Daza Cruz Jul 27 '13 at 3:38
By MWE @Nasser meant a minimal working example. I.e., please explain in detail how pwF is defined. But perhaps you already got it to work without InputForm? –  Jens Jul 27 '13 at 4:31
With \\InputFormat you mean //InputForm, right? And you know that you don't need to convert the 2D form of Piecewise to 1D in an assignment? –  Sjoerd C. de Vries Jul 27 '13 at 5:53
You are right, I was confused and typed \\InputFormat. –  Daniel Fernando Daza Cruz Jul 27 '13 at 16:14
add comment

closed as off-topic by Yves Klett, Simon Woods, Artes, Michael E2, rm -rf Jul 27 '13 at 16:22

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Yves Klett, Simon Woods, Artes, rm -rf
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 1 down vote accepted

InputForm is a formatting wrapper(1),(2). It should not be used as input to another function such as Plot.

You do not need to "convert" the two dimensional form of Piecewise in your function; it may be used as is:

enter image description here

If you were to include InputForm in the definition, which again you need not do, you could strip the wrapper using First:

enter image description here

share|improve this answer
add comment

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