Message Boards Message Boards

creating a package and encoding for CDF deployment?

Posted 8 years ago

Hello, I am trying to teach myself both Mathematica and CDF deployment. I created a simple example given below

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 = DGL[f, xR, xL, np, nw];]], 
 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}, Initialization :> (DGL[f_, xR_, xL_, np_, nw_] := 
 NumberForm[NIntegrate[f, {x, xL, xR}, WorkingPrecision -> nw], 
  np])]]

enter image description here

As you can see I created a function DGL for the integration. My goal is the able to create a package and encode my function. For that I followed this tutorial Wolfram's Tutorial

I created the package called INTSourceCode

BeginPackage["INTSourceCode`"];DGL[f_,xR_,xL_,np_,nw_]:=NumberForm[NIntegrate[f,{x,xL,xR},WorkingPrecision->nw],np];SetAttributes[DGL,{ReadProtected,Protected,Locked}];EndPackage[];

and update my code as follows

Manipulate[DynamicModule[{f = Sin[x], xR = 1, xL = 0, 
Res = 0.4596976941318603}, Column[
{Style["1D Definite Integral Calculator", "Function"] logo,
 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 = INTSourceCode`DGL[f, xR, xL, np, nw];]], 
 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},
 Initialization :> (
Needs["INTSourceCode`"];
) ]]

The idea is to follow the tutorial, encode the package and have a secure CDF. But when I use the package the code is not working. I have the package in the same folder as the main code. I dont know what is my mistake.

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