1
$\begingroup$

I have created a code in Wolfram Mathematica. I want it to be CDF file. I selected File-> CDF Export -> Standalone. I was told that the file doesn't work but I don't know why.

Clear[f, der1]
Manipulate[Grid
  [{{Column
     [{Row[{Framed[Style["Functions", Bold, White, 25], 
         Background -> Red, RoundingRadius -> 1
         ]}]}]},        
   {Column
     [{
      Row[{"Type the function:   ", 
        InputField[Dynamic[f], Background -> LightYellow]}],    
      Row[{"Domain: ", 
        dom = Simplify[FunctionDomain[f, x, Reals]]}],     
      Row[{"Range: ", FunctionRange[f, x, y]}],
      Row[{"f[0] ", f /. x -> 0}],
      Row[{"f[x]=0 ", Simplify[x /. Solve[f == 0, x, Reals]]}],
      Row[{"First derivative ", der1 = Simplify[D[f, x]]}],  
      Row[{"Second derivative ", der2 = Simplify[D[f, x, x]]}],
      Row[{"First derivative = 0 ", 
        zeder = Solve[der1 == 0, x ]}],      
      Row[{"Function is increasing: ", Reduce[der1 > 0, x]}],
      Row[{"Function is decreasing: ", Reduce[der1 < 0, x]}],
      Row[{"Points of discontinuity: ", 
        dis = Solve[Denominator[Together[f]] == 0, Reals]}],
      Row[{"First derivative - points of discontinuity: ", 
        noder = Solve[Denominator[Together[der1]] == 0, Reals]}],
      Row[{"Extrema: ", 
        extr = Union[
          Sort[Join[{axisxfrom}, {axisxto}, {zeder}, {noder}, \
{dis}]]]}], 
      Row[{"Maximal values ", 
        Maximize[{f, axisxfrom <= x <= axisxto}, x]}],
      Row[{"Minimal values: ", 
        Minimize[{f, axisxfrom <= x <= axisxto}, x]}], 
      Row[{"Function is convex ", Reduce[der2 > 0, x]}],
      Row[{"Function is concave ", Reduce[der2 < 0, x]}],
      Plot[f, {x, axisxfrom, axisxto}, 
       PlotRange -> {axisyfrom, axisyto}, Background -> LightGreen]
      }]}}],
 {axisxfrom, -5}, {axisxto, 5}, {axisyfrom, -2}, {axisyto, 2}] 
$\endgroup$

2 Answers 2

4
$\begingroup$

Your main problem, inoperable CDF, results from attempting to use a InputField in your code. In this documentation article, under the section Interactivity in .cdf Files, you will find the statement

All interactive content must be generated with the Manipulate command and may only use mouse-driven elements, such as Slider, Locator, Checkbox, PopupMenu, etc.

The statement clearly prohibits the use of any GUI widget that permits the user to enter an arbitrary expression from the keyboard. I believe this is required to make sure the Manipulate expression has complete control over what the data it handles and that the input expression, when evaluated, can not take over an evaluator.

Instead you might use a pop-up menu with a list of functions the user can choose from. Here is an example of a Manipulate expression that implements something along the lines of the one you created, but which appears to produce a functional CDF file. I don't think it fixes all the problems of your code — you will have to work further to eliminate the residual bugs.

DynamicModule[{f, dom, der1, der2, zeder, dis, noder, extr},
  Manipulate[
    Column[{
      Item[
        Framed[
          Style["Functions", Bold, White, 16],
          Background -> Red, RoundingRadius -> 4],
        Alignment -> Center],
      Row[{"Choose a function: ", PopupMenu[Dynamic @ f[x], {x^2, x^3, E^x}]}], 
      Row[{"Domain: ", dom = Simplify[FunctionDomain[f[x], x, Reals]]}],
      Row[{"Range: ", FunctionRange[f[x], x, y]}], 
      Row[{"f[0] ", f[x] /. x -> 0}], 
      Row[{"f[x]=0 ", Simplify[x /. Solve[f[x] == 0, x, Reals]]}], 
      Row[{"First derivative ", der1 = Simplify[D[f[x], x]]}], 
      Row[{"Second derivative ", der2 = Simplify[D[f[x], x, x]]}], 
      Row[{"First derivative = 0 ", zeder = Solve[der1 == 0, x]}], 
      Row[{"Function is increasing: ", Reduce[der1 > 0, x]}], 
      Row[{"Function is decreasing: ", Reduce[der1 < 0, x]}], 
      Row[
        {"Points of discontinuity: ", 
         dis = Solve[Denominator[Together[f[x]]] == 0, Reals]}], 
      Row[
        {"First derivative - points of discontinuity: ", 
         noder = Solve[Denominator[Together[der1]] == 0, Reals]}], 
      Row[
        {"Extrema: ", 
         extr = 
           Union[Sort[Join[{axisxfrom}, {axisxto}, {zeder}, {noder}, {dis}]]]}], 
      Row[{"Maximal values ", Maximize[{f[x], axisxfrom <= x <= axisxto}, x]}], 
      Row[{"Minimal values: ", Minimize[{f[x], axisxfrom <= x <= axisxto}, x]}],
      Row[{"Function is convex ", Reduce[der2 > 0, x]}], 
      Row[{"Function is concave ", Reduce[der2 < 0, x]}], 
      Plot[f[x], {x, axisxfrom, axisxto},
        PlotRange -> {axisyfrom, axisyto},
        Background -> LightGreen]}],
  {axisxfrom, -5},
  {axisxto, 5},
  {axisyfrom, -2},
  {axisyto, 2},
  Initialization :> (Clear[x, y]; f[x_] := x^2)]]

demo

Notes

  1. I could see no good reason for using both Grid and Row and Columen, so I eliminated the use of Grid.
  2. The above code will not work for arbitrary functions. For instance, putting Sin[x] on the pop-up menu will produce errors.
  3. The code you wrote to generate properties for function is not very robust. You must improve it or pick the functions the user can choose very carefully.
  4. You may be wondering why the control forms like {axisyto, 2}, which produce input fields, are permitted. I believe they are permitted because they are restricted by the internals of Manipulate to accepting only numerical values.
$\endgroup$
2
  • $\begingroup$ Thanks, but it has to work for all functions - not just PopupMenu functions $\endgroup$
    – Lucy
    Commented Aug 27, 2018 at 9:11
  • $\begingroup$ @Lucy. AFAIK that can't be done with a CDF. Perhaps someone with more CDF experience or a better grasp of Mathematic than I have will contribute an answer that will meet your requirements, but I can't. $\endgroup$
    – m_goldberg
    Commented Aug 27, 2018 at 14:04
0
$\begingroup$

The code works just fine, but when stipulating a function in the input field, it needs to be explicitly in x. Since the default case is just f, which is not a function of x, the code acts accordingly.

I tested several functions (e.g. x, x+1, x^2) which explicitly included x and it worked just fine.

Also note that when dealing with input fields in Manipulate, in order to change the output the way you want, the change needs to be executed with just Enter and not Shift+Enter in the input field.

$\endgroup$
4
  • $\begingroup$ Thank you, but i executed the change with Enter in the input field. So, I don't know why it didn't work. I've heard that the problem can be the Input field. What do you think? Or could I convert it in a wrong way? $\endgroup$
    – Lucy
    Commented Aug 26, 2018 at 16:35
  • $\begingroup$ Could you elaborate on exactly what's not working? Error messages or it's just not outputting anything, etc? $\endgroup$ Commented Aug 26, 2018 at 16:46
  • $\begingroup$ It is my school project and I sent to my teacher .nb file and .cdf file. He answered me that cdf file does not work. He doesn't want to tell me more about it. I'm desperate. $\endgroup$
    – Lucy
    Commented Aug 26, 2018 at 17:03
  • $\begingroup$ I tried to select File->CDF Preview->CDF Player and it didn't work. Do you know why? Maybe this is the problem... $\endgroup$
    – Lucy
    Commented Aug 26, 2018 at 17:16

Your Answer

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

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