1
$\begingroup$

I want to deploy an interactive CDF that may depend on several functions. How do I define those functions? I'm using Manipulate, I defined the function inside it prior to returning the value I want, that is

CDFDeploy["test01",
 Manipulate[
  f = Function[x, x^2];
  f[z],
  {z, 0, 10}]]

This indeed yields what I want

enter image description here

I have, however, a few questions:

  • Is there a better way of defining functions to be used within a CDF? I wonder if it can be more efficient. For example, defining f before Manipulate doesn't work.
  • When I try to use, for example, f[x_] := x^2, the notebook starts to blink and freezes. Any idea why?
  • I've been mostly using Manipulate, but I've also heard of DynamicModule for interactive CDFs. I'm not very acquainted with it. Could it be useful in my case?
$\endgroup$
  • 5
    $\begingroup$ Define inside using Initialization or outside using SaveDefinitions. $\endgroup$ – Kuba Jan 14 at 15:32
  • 1
    $\begingroup$ Great! I've added an answer for the record, based on your comment. Thank you. $\endgroup$ – sam wolfe Jan 15 at 22:26
1
$\begingroup$

Following the comment by Kuba ♦ in the comment section, using Initialization solves my problem

CDFDeploy["test01",
 Manipulate[
  f[z],
  {z, 0, 10},
  Initialization :> (f[x_] := x^2)]]
| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.