1
$\begingroup$

This is most likely a very naive question, but I'm puzzled as to why the following code runs smoothly in Mathematica 12.1.1.0 but does not generate a working plot in Wolfram Player 12.1.1.0.

f[a_, x_] := Sin[a x];
Manipulate[ 
 Plot[f[a, x], {x, 0, 20}],
 {{a, 1}, 0, 3}
 ]

In Mathematica, I get the expected interactive Sin graph. In Wolfram Player, I get the axes and the slider, but no graph.

If I replace the separate function definition with

Manipulate[Plot[Sin[a x]....

everything works fine in Wolfram Player.

I must not understand what Wolfram Player is supposed to do, but I've struggled to find adequate documentation.

Thank you in advance.

$\endgroup$
5
  • $\begingroup$ I wonder if this might be an OS-specific problem. $\endgroup$ Nov 29, 2020 at 17:17
  • 1
    $\begingroup$ Why not use the SaveDefinitions -> True option of Manipulate? $\endgroup$ Nov 29, 2020 at 18:24
  • $\begingroup$ Rolf, I don't understand why that works, but it works. Thank you so much! If you want to turn it into an answer I could wrap up the question as answered, or I can write something myself if you prefer. $\endgroup$
    – Corvus
    Nov 29, 2020 at 18:47
  • 1
    $\begingroup$ Have you tried Manipulate[Plot[f[a, x], {x, 0, 20}], {{a, 1}, 0, 3}, Initialization :> (f[a_, x_] := Sin[a x])] $\endgroup$
    – Bob Hanlon
    Nov 29, 2020 at 20:04
  • $\begingroup$ Bob, this works as well. Thank you. I guess I don't understand the theory behind what Wolfram Player is supposed to do. I would have thought it would execute the function definitions that are part of the same initialization cell as the Manipulate command. Maybe I'm misunderstanding that? $\endgroup$
    – Corvus
    Nov 29, 2020 at 20:16

1 Answer 1

1
$\begingroup$

This isn't working likely because the function in wolfram player hasn't been initiated yet. If you turn that cell into an initialization cell and reexport to cdf it should work fine, you can do this by highlighting the cell right clicking the bar/bracket thing on the right side and setting it to Initialization, this should fix the issue.

I unfortunately couldn't replicate the problem on my machine, so this is mostly just conjecture and knowledge that Plot[] produces blank graphics when variables or functions are missing or are not numeric.

$\endgroup$
1
  • $\begingroup$ Thank you. Unfortunately, I had tried that and it doesn't either. I went back and tried from scratch, cutting and pasting the text from here, making it an initialization cell, and the problem persists. $\endgroup$
    – Corvus
    Nov 29, 2020 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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