# Embed NDSolveValue function in Manipulate for CDF?

**URL:** <https://community.wolfram.com/t/embed-ndsolvevalue-function-in-manipulate-for-cdf/13887>\
**Category:** Questions\
**Tags:** computable-document-format, equation-solving, interface-construction\
**Created:** [April 10, 2019, 9:43am UTC](https://community.wolfram.com/t/embed-ndsolvevalue-function-in-manipulate-for-cdf/13887 "2019-04-10T09:43:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![christopheterrier](https://avatars.discourse-cdn.com/v4/letter/c/f17d59/32.png) [@christopheterrier](https://community.wolfram.com/u/christopheterrier)\
**Post date:** [April 10, 2019, 9:43am UTC](https://community.wolfram.com/t/embed-ndsolvevalue-function-in-manipulate-for-cdf/13887/1 "2019-04-10T09:43:03Z")

</div>

Hello,  
I’m usually writing Notebooks and sharing them with students. Our new students won’t have Mathematica licenses anymore, so that I’m starting coding my notebooks in CDF compatible format.  
But I’m facing some troubles. For example, I’m unable to make this code working for CDF:

```
ClearAll["Global`*"];
tmax = 2 \[Pi];
{xsol, ysol} = 
  NDSolveValue[{x'[t] == y[t], y'[t] == -x[t], x[0] == 1, 
    y[0] == 0}, {x, y}, {t, 0, tmax}];

Manipulate[ 
 Graphics[Point[{xsol[t], ysol[t]}], PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}}],
 {t, 0, tmax}
  ]

```

Could someone give me a hint how to solve this?  
Thanks!

---

<div class="post-metadata">

**Author:** ![gdelfino](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/gdelfino/32/41294_2.png) [@gdelfino](https://community.wolfram.com/u/gdelfino)\
**Post date:** [April 10, 2019, 4:00pm UTC](https://community.wolfram.com/t/embed-ndsolvevalue-function-in-manipulate-for-cdf/13887/2 "2019-04-10T16:00:41Z")

</div>

When you deploy to CDF, cells are not evaluated, only dynamic objects like the output of Manipulate. When that Manipulate output is evaluated by the CDF Player the variables xsol, ysol and tmax are undefined so it doesn’t work. So you have to make everything self contained by hand:

```
With[{tmax = 2 \[Pi]}, 
 With[{solutions = NDSolveValue[{x'[t] == y[t], y'[t] == -x[t], x[0] == 1, y[0] == 0}, {x, y}, {t, 0, tmax}]},
  Manipulate[
   Graphics[Point[{xsol[t], ysol[t]}], PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}}],
   {t, 0, tmax},
   Initialization :> ({xsol, ysol} = solutions)]]]

```

Or just add a `SaveDefinitions` option to your Manipulate which is much easier (and dangerous).

---

<div class="post-metadata">

**Author:** ![christopheterrier](https://avatars.discourse-cdn.com/v4/letter/c/f17d59/32.png) [@christopheterrier](https://community.wolfram.com/u/christopheterrier)\
**Post date:** [April 11, 2019, 7:58am UTC](https://community.wolfram.com/t/embed-ndsolvevalue-function-in-manipulate-for-cdf/13887/3 "2019-04-11T07:58:52Z")

</div>

Thank you very much. I think I still have things to learn with Mathematica. I tried to solve a more complicated code in the way you showed me, and my expressions are too poorly defined…
