# How can I make CDF which uses user defined function

I have a user defined function which is called many times in the code. I want to ask that when I am deploying the code toCDF, I need to define that user defined function also. I tried it using DynamicModule and With. But none is working. How should I give that user defined function so that it can be deployed into CDF.

-
Check out the Initialization option. See this QA: mathematica.stackexchange.com/questions/9476/…. –  kale Aug 30 '12 at 12:49
No,I am calling the function and appending it to get the list. –  Jennifer Aug 30 '12 at 13:08

Here is a small example. I saved it to CDF and it works as is in the CDF. It has small functions in the Initialization section that are used by the Dynamics inside the DynamicModule to run the simple simulation to illustrate the idea.

Notice that this is not much different from putting all your functions in the Initialization section of the Manipulate, since Manipulate is basically a DynamicModule. So same idea.

DynamicModule[{sol, angle, bob, r, time = 0, animationRate = 1, y},

Dynamic@Grid[{{Trigger[Dynamic[time], {0, Infinity, 0.01},
animationRate,
AppearanceElements -> {"PlayPauseButton", "ResetButton"}],
Style["time (sec)", 10], Dynamic[time]},
{Dynamic@
Show[Graphics[{{Dashed, Gray, Thin, Circle[{0, 0}, 1]}, {Red,
Thick, Line[{{0, 0}, bob}]},
{Blue, PointSize[0.1], Point[bob]}},
ImagePadding -> 10], ImageSize -> 300], SpanFromLeft}
}, Frame -> True, Alignment -> Left],

Initialization :> (
sol :=
First@NDSolve[{y''[t] + 0.1 y'[t] + Sin[y[t]] == 1.5 Cos[t],
y[0] == Pi/4, y'[0] == 0}, y, {t, time, time + 1},
Sequence@ndsolveOptions];
bob := {Sin[(y /. sol)[time]], -Cos[(y /. sol)[time]]};

ndsolveOptions = {MaxSteps -> Infinity,
Method -> {"StiffnessSwitching",
Method -> {"ExplicitRungeKutta", Automatic}},
AccuracyGoal -> 10, PrecisionGoal -> 10}
)]


-