Message Boards Message Boards

Execute two functions from two packages with a common button?

Posted 8 years ago

I am developing a .nb (further to be a CDF) where I am loading two packages. One package is taking numerical integral and the other is taking symbolic one. I would like to be able execute both packages with one button click. Here is the main file

Manipulate[
 DynamicModule[{f = Sin[x], xR = 1, xL = 0, 
   Res = 0.4596976941318603`16, NRes = 0.4596976941318603`16}, 
  Column[{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 = TFPackageSourceCodeNum`WD1Int[f, xR, xL, np, nw];]],
    Button[Style["Calculate", Green, Bold], 
     Dynamic[NRes = TFPackageSourceCodeSym`ND1Int[f, xR, xL, nw];]],
    Row[{"Result", InputField[Dynamic[Res], Enabled -> False]}, 
     Spacer[51]],
    Row[{"Symbolic", InputField[Dynamic[NRes], Enabled -> False]}, 
     Spacer[35]],
    Row[{"Difference", 
      InputField[Dynamic[NRes - Res], Enabled -> False]}, 
     Spacer[20]],
    }]], {{np, 16, "NumberFormat"}, 
  ControlPlacement -> Bottom}, {{nw, 16, "WorkingPrecision"}, 
  ControlPlacement -> Bottom}, 
 Initialization :> (Get[
     FileNameJoin[{NotebookDirectory[
        EvaluationNotebook[]], {"TFPackageSourceCodeSym.wl", 
        "TFPackageSourceCodeNum.wl"}}]];)]

I grouped the functions under one button using { }

Button[Style["Calculate", Green, 
  Bold], {Dynamic[
   Res = TFPackageSourceCodeNum`WD1Int[f, xR, xL, np, nw];],
  Dynamic[NRes = TFPackageSourceCodeSym`ND1Int[f, xR, xL, nw];]}]

But it did not work. How I can do this ?

POSTED BY: Erdem Uguz
2 Replies
Posted 8 years ago

Thank you Craig. It worked beautifully.

POSTED BY: Erdem Uguz

Dear Erdem, You don't need to wrap Dynamic around the Set.

Notice the difference between the the behavior of the first and second calculation in the following:

Dynamic[{res1, res2}]

Button["Calculate", {Dynamic[res1 = Integrate[Sin[x], {x, 0, 1}]], 
  res2 = NIntegrate[Sin[x], {x, 0, 1}]}]

I hope this helps

POSTED BY: W. Craig Carter
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