Message Boards Message Boards

0
|
6464 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Create named InputFields and sizing on CDF

Posted 8 years ago

Hello, I am developing a toy application to teach me how to generate a more complex CDF app. The current toy app is taking integral.

Manipulate[
  DynamicModule[{f = Sin[x], xR = 1, xL = 0, Res = 0.4596976941}, 
   Column[{ InputField[Dynamic[xL], Number], 
     InputField[Dynamic[xR], Number], InputField[Dynamic[f]], 
     Button["Calculate", 
      Dynamic[Res = 
         NumberForm[
          NIntegrate[f, {x, xL, xR}, WorkingPrecision -> nw], np];]], 
     InputField[Dynamic[Res]], 
     Dynamic[If[fp == True, Plot[f, {x, xL, xR}]]]}]], {{np, 10, 
    "NumberFormat"}, 10, 30, 1}, {{nw, 16, "WorkingPrecision"}, 10, 
   30, 1}, {{fp, True, "Plot the function"}, {False, True}, 
   Checkbox}]

enter image description here

But there are couple of problems that I am trying to solve.

  1. I would like to have name tags on the left or top of each input fields. FieldHint does not work.

    Manipulate[
      DynamicModule[{f, xR, xL, Res}, 
       Column[{
         InputField[Dynamic[xL], Number, FieldHint -> "Lower Limit"], 
         InputField[Dynamic[xR], Number, FieldHint -> "Upper Limit"], 
         InputField[Dynamic[f], FieldHint -> "Function"], 
         InputField[Dynamic[Res], FieldHint -> "Result"], 
         Button["Calculate", 
          Dynamic[Res = 
             NumberForm[
              NIntegrate[f, {x, xL, xR}, WorkingPrecision -> nw], np];]], 
         Dynamic[If[fp == True, Plot[f, {x, xL, xR}]]]}]], {{np, 10, 
        "NumberFormat"}, 10, 30, 1}, {{nw, 16, "WorkingPrecision"}, 10, 
       30, 1}, {{fp, False, "Plot the function"}, {False, True}, 
       Checkbox}]
    

There is no problem with Lower and Upper Limit in here but I don't know why I don't get "Function" and "Result" enter image description here And to be honest I prefer to have the name tags with an example calculation.

  1. I tried to make the plotting also part of the push button but it is not working (I simply moved the ] of Button to the end of the plotting). Also when I dont have the plot I have a string "Null" which I don't like. Is there a way of getting rid off that? And how can I make the size of the plot bigger?
  2. The last thing I could not figure it out is to limit xL and xR inputs to a number. I specified in the inputfield that the input is number but when I enter I get an error but I thought it supposed to simply not update (according to help document "The input field will not be updated if the input is not of the specified type")

Thank you for the help. As I said I am trying to create a more complex app and this app is helping me to learn, Thank you for the help

POSTED BY: Erdem Uguz
3 Replies
Posted 8 years ago

I had some help to improve the interface little more. http://mathematica.stackexchange.com/questions/113254/correcting-problems-with-the-controls-in-a-manipulate/113404#113404 Yes I know I am posting questions in both forums but I think it is not cheating ;)

So here what final code looks like but there are still some stuff that I would like figure out.

Manipulate[
  DynamicModule[{f = Sin[x], xR = 1, xL = 0, 
    Res = 0.4596976941318603}, Column[
    {Style["1D Definite Integral Calculator", "Function"],
     Row[{"Lower Limit ", InputField[Dynamic[xL], Number]}, Spacer[5]],
     Row[{"Upper Limit ", InputField[Dynamic[xR], Number]}, Spacer[5]],
     Row[{"Function  ", InputField[Dynamic[f]]}, Spacer[20]], 
     Button[Style["Calculate", Green, Bold], 
      Dynamic[Res = 
         NumberForm[
          NIntegrate[f, {x, xL, xR}, WorkingPrecision -> nw], np];]], 
     Row[{"Result", InputField[Dynamic[Res]]}, Spacer[5]], 
     If[fp == True, 
      InputField[
       Dynamic[Plot[f, {x, xL, xR}, Dynamic[PlotLabel -> f]]], 
       FieldSize -> {30, 15}]],
      Button[
      Mouseover[Style["http://www.wolfram.com", "Hyperlink"], 
       Style["http://www.wolfram.com", "HyperlinkActive"]], 
      NotebookLocate[{URL["http://www.wolfram.com"], None}], 
      Appearance -> None]
     },

    ]], {{fp, True, "Plot the function"}, {False, True}, Checkbox, 
   ControlPlacement -> Bottom}, {{np, 16, "NumberFormat"}, 5, 30, 1, 
   ControlPlacement -> Bottom}, {{nw, 16, "WorkingPrecision"}, 10, 30,
    1, ControlPlacement -> Bottom}]]

enter image description here The problems I would like to solve are: 1- Even though in the DynamicModule (at the beginning) I defined Res=0.4596976941318603 but I can't see all the digits in the panel 2- I could not able to adjust the plot size as I am able to do the fieldsize. Also when I change the function and return the plot is updated. I prefer plot is updated with Calculate button but till now I could not figure that out. 3- InputFields for xR and xL supposed to only get numeric values and incase user inputs character the field should not updated (according to help document) but that is not the case.

Hopefully this little toy problem is helping others too.

POSTED BY: Erdem Uguz
POSTED BY: Henrik Schachner
Posted 8 years ago

Here is a solution that I found for naming the inputfields

Manipulate[
  DynamicModule[{f = Sin[x], xR = 1, xL = 0, Res = 0.4596976941}, 
   Column[{
     Style["Lower Limit:", "Function"], 
     InputField[Dynamic[xL], Number],
     Style["Upper Limit:", "Function"], 
     InputField[Dynamic[xR], Number],
     Style["Function:", "Function"], InputField[Dynamic[f]],
     Style["Result:", "Function"], InputField[Dynamic[Res]], 
     Button["Calculate", 
      Dynamic[Res = 
         NumberForm[
          NIntegrate[f, {x, xL, xR}, WorkingPrecision -> nw], np];]], 
     Dynamic[If[fp == True, Plot[f, {x, xL, xR}]]]}]],
  {{np, 10, "NumberFormat"}, 10, 30, 1, ControlPlacement -> Bottom},
  {{nw, 16, "WorkingPrecision"}, 10, 30, 1, 
   ControlPlacement -> Bottom},
  {{fp, True, "Plot the function"}, {False, True}, Checkbox, 
   ControlPlacement -> Bottom}]]

But I still don't know how to fix the "Null" when I dont want the plot and also even though I specify the inputfields for xL and xR I get an error when I put down a character. According to help document this should not happen.

POSTED BY: Erdem Uguz
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract