Message Boards Message Boards

GROUPS:

Encoded Package works in .nb but not in Enterprise CDF?

Posted 5 years ago
5019 Views
|
4 Replies
|
2 Total Likes
|

Hello I am working on learning Enterprise CDF development. I use encoded package and in .nb format I have no problem but when I export using Enterprise CDF the code is not working. I saved all files ( notebook file, CDF and encoded package) under the same folder inside the $Path. I don't know why .nb file is working but CDF does not.

Manipulate[
 DynamicModule[{f = Sin[x], xR = 1, xL = 0, 
   Res = 0.4596976941318603`16}, 
  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 = TF1DINTPackage`D1Int[f, xR, xL, np, nw];]], 
    Row[{"Result", InputField[Dynamic[Res], Enabled -> False]}, 
     Spacer[51]], 
    Row[{"Plot the Function ", 
      Checkbox[Dynamic[fp], {False, True}]}],
    If[fp == True, 
     InputField[
      Dynamic[Plot[f, {x, xL, xR}, Dynamic[PlotLabel -> f], 
        ImageSize -> Full]], 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]}]], {{np, 16, "NumberFormat"}, 
  ControlPlacement -> Bottom}, {{nw, 16, "WorkingPrecision"}, 
  ControlPlacement -> Bottom}, 
 Initialization :> (Needs["TF1DINTPackage`"])]

And the package is

BeginPackage["TF1DINTPackage`"];
D1Int[f_,xR_,xL_,np_,nw_]:=Module[{xLcheck,xRcheck},xLcheck=NumberQ[xL];
xRcheck=NumberQ[xR];
If[xLcheck==True&&xRcheck==True,ResultTF=SetPrecision[NIntegrate[f,{x,xL,xR},WorkingPrecision->Re[IntegerPart[nw]]],Re[IntegerPart[np]]],"Enter numeric inputs for Lower and Upper Limits"]];
SetAttributes[D1Int,{ReadProtected,Protected,Locked}];
EndPackage[];

I attached the encoded version of the package too. Thank you for the help.

Attachments:
4 Replies

Hello, this works:

Manipulate[{x,xR,xL,f,Res},Column[{Style["1D Definite Integral Calculator","Subsubitem"],

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],Res=TF1DINTPackage`D1Int[f,x,xR,xL,np,nw];],Row[{"Result",InputField[Dynamic[Res],Enabled->False]},Spacer[51]],Row[{"Plot the Function ",Checkbox[Dynamic[fp],{False,True}]}],

Dynamic@If[fp,Plot[f[x],{x,xL,xR},PlotLabel->f,ImageSize->200]],

Button[Mouseover[Style["http://www.wolfram.com","Hyperlink"],Style["http://www.wolfram.com","HyperlinkActive"]],NotebookLocate[{URL["http://www.wolfram.com"],None}],Appearance->None]}
],
{{np,16,"NumberFormat"},ControlPlacement->Bottom},{{nw,16,"WorkingPrecision"},ControlPlacement->Bottom},
Initialization:>(f=Sin;xR=1;xL=0;Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]],"TF1DINTPackage.m"}]];
Res=TF1DINTPackage`D1Int[f,x,xR,xL,16,16];)]


(* ::Package:: *)

BeginPackage["TF1DINTPackage`"];
D1Int::usage="";
Begin["`Private`"];
D1Int[f_,x_,xR_?NumberQ,xL_,np_,nw_]:=Module[{xLcheck,xRcheck},xLcheck=NumberQ[xL];
xRcheck=NumberQ[xR];
If[xLcheck==True&&xRcheck==True,SetPrecision[NIntegrate[f[x],{x,xL,xR},WorkingPrecision->Re[IntegerPart[nw]]],Re[IntegerPart[np]]],"Enter numeric inputs for Lower and Upper Limits"]];
SetAttributes[D1Int,{ReadProtected,Protected,Locked}];
End[];
EndPackage[]
Posted 5 years ago

Thank you I have two questions that I could not figure out.

In your version I can't enter function like Cos[x]+Sin[x] because you defined x in the function. I removed that x variable but I am getting an error.

Second, why there is a box of result and variable at the bottom?

Thank you for the help.

enter image description here

Sorry, this should work better.

Manipulate[
 Column[{Style["1D Definite Integral Calculator", "Subsubitem"], 
   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], 
    Res = TF1DINTPackage`D1Int[f, x, xR, xL, np, nw];],

   Row[{"Result", InputField[Dynamic[Res], Enabled -> False]}, 
    Spacer[51]], 
   Row[{"Plot the Function ", Checkbox[Dynamic[fp], {False, True}]}], 
   Dynamic@If[fp, 
     Plot[f[x], {x, xL, xR}, PlotLabel -> f, ImageSize -> 200], ""],

   Button[
    Mouseover[Style["http://www.wolfram.com", "Hyperlink"], 
     Style["http://www.wolfram.com", "HyperlinkActive"]], 
    NotebookLocate[{URL["http://www.wolfram.com"], None}], 
    Appearance -> None]


   }], {{np, 16, "NumberFormat"}, ControlPlacement -> Bottom},
 {{nw, 16, "WorkingPrecision"}, ControlPlacement -> Bottom},

 Initialization :> (f = Sin[#] + Cos[#] &; xR = 1; xL = 0; 
   Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]], 
      "TF1DINTPackage.m"}]];
   Res = TF1DINTPackage`D1Int[f, x, xR, xL, 16, 16];)]
Posted 5 years ago

I am trying to adapt you solution to my program but it is not working. I would like to understand the difference because I am working on this example for learning on purpose. I would like to understand why this is not working.

Manipulate[
 DynamicModule[{f = Sin[x], xR = 1, xL = 0, 
   Res = 0.4596976941318603`16}, 
  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 = TFPackage`WD1Int[f, xR, xL, np, nw];]], 
    Row[{"Result", InputField[Dynamic[Res], Enabled -> False]}, 
     Spacer[51]], 
    Row[{"Plot the Function ", 
      Checkbox[Dynamic[fp], {False, True}]}],
    If[fp == True, 
     InputField[
      Dynamic[Plot[f, {x, xL, xR}, Dynamic[PlotLabel -> f], 
        ImageSize -> Full]], 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]}]], {{np, 16, "NumberFormat"}, 
  ControlPlacement -> Bottom}, {{nw, 16, "WorkingPrecision"}, 
  ControlPlacement -> Bottom}, 
 Initialization :> (Get[
     FileNameJoin[{NotebookDirectory[EvaluationNotebook[]], 
       "TFPackage.m"}]];)]

And the package is

BeginPackage["TFPackage`"];
WD1Int::usage="";
Begin["`Private`"];
WD1Int[f_,xR_,xL_,np_,nw_]:=Module[{xLcheck,xRcheck},xLcheck=NumberQ[xL];
xRcheck=NumberQ[xR];
If[xLcheck==True&&xRcheck==True,WResultTF=SetPrecision[NIntegrate[f,{x,xL,xR},WorkingPrecision->Re[IntegerPart[nw]]],Re[IntegerPart[np]]],"Enter numeric inputs for Lower and Upper Limits"]];
SetAttributes[WD1Int,{ReadProtected,Protected,Locked}];
End[];
EndPackage[];

It is almost exactly same I can't understand what is the problem.

Thank you for the help

enter image description here

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