Approximate UnitStep for use in Enterprise CDF

The following Manipulate code displays the VectorPlot for all functions. (This code is a subset of a more extensive notebook which is based on the structure you see below. Consequently, I need to preserve the structure below.) But when previewed as an Enterprise CDF (in the Wolfram CDF Player Pro), non-smooth functions as Sign[t] or UnitStep[t] do not display at all.

Manipulate[
sf@dx[diffEq],
Style["Enter f(t,x)"],
{{diffEq, x^2 - t, "dx/dt"}},
Initialization :>
(
dx[de_] := de;
sf[dx_] :=
VectorPlot[{1, dx}, {t, -2, 2}, {x, -2, 2}, VectorPoints -> 17,
VectorScale -> {0.03, Automatic, None},
VectorStyle -> {{Red, Arrowheads}}, ImagePadding -> 1,
PerformanceGoal -> "Speed"];
)
]

My proposed solution to remedy this problem is to approximate UnitStep[t] with (1 + Erf[a t])/2 where a is some large positive number, say, a > 100. My idea was to insert the line

If[MemberQ[diffEq, u[t]], u[t] /. (1 + Erf[a t])/2];

immediately after the Manipulate command so as to translate the input expression u[t] to (1 + Erf[a t])/2. Clearly this didn't work for me and I don't know where to go next. In essence, I want to define a new function u[t] as a legitimate input and to be able to use it as if it were part of the Mathematica language.

BTW, I posted a question recently regarding this issue, but that post did not provide the framework that I need.

• I have created a dfield knockoff which works well for all smooth functions that I have entered in the input field of an Enterprise CDF. But Abs, UnitStep, etc, are not accepted - the CDF plot window just blanks. Has anyone been able to Initialize a Needs command to store the missing functions? – Stephen Sep 21 '15 at 19:35

Looking at the features in How Player Pro Compares for EnterpriseCDF. In the Input/Output section the "Keyboard entry" lines are basically saying that there is limited functionality when entering text to be interpreted as Wolfram Language. I believe this is to prevent the creation of basically a complete interactive version of Mathematica through a CDF that simply interprets text into Wolfram code.

If you want to give more options for the plot then you need to explicitly list them in your manipulate.

Manipulate[Plot[f, {x, -2 Pi, 2 Pi}],
{f, {Sin[x], Abs[x], UnitStep[x]}}]

Hope this helps.

Update

I think you want to do something like this, correct?

Manipulate[
Plot[f[x + a], {x, -2 Pi, 2 Pi},
PlotLabel -> (StringTemplate["1[x + 2]"][f, a])],
{f, {Sin, Abs, UnitStep}},
{a, 1, InputField}]
• Is it possible to encode Abs, etc, in my code yet plot variations of them like UnitStep[x-1] without listing them as you have done? – Stephen Sep 19 '15 at 13:02
• Basically I want to create an Enterprise CDF so I can enter and plot the smooth functions and variations of just the two nonsmooth functions Abs and UnitStep – Stephen Sep 19 '15 at 13:13
• @Stephen I added what I understand it is you are trying to do. See the update. – Edmund Sep 19 '15 at 13:26
• The update is helpful but does not provide the flexibility I want. For instance, suppose that I want to enter x*(UnitStep[x]-UnitStep[x-1])? – Stephen Sep 19 '15 at 14:23
• @Stephen You need to think out what short of combinations and shift/scale parameters you need and then program that in. You can make combinations of functions with another function variable and so on. You'll need to do a little bit of programming but it is definitely possible. – Edmund Sep 19 '15 at 14:34

I have found a workaround by defining, for example,

u[z_] := UnitStep[z];
abs[z_] := Abs[z];

in the Initialization section. Upon exporting to Enterprise CDF, I can, for example, type u[t] in the entry box and get the desired slope field.

Regrettably, this workaround does have a flaw: upon typing u[t] in the entry box and then hitting the Enter key, the expression u[t] is replaced by UnitStep[t]. I want to insure that the original expression u[t] remains in the entry box after entering it. One does not need to have an Enterprise version of MMA to test this as the issue is apparent from the nb code itself. I don't know how to code this property into my nb file. Should post this question as a new one?