# Plotting functions within a Manipulate

**URL:** <https://community.wolfram.com/t/plotting-functions-within-a-manipulate/19527>\
**Category:** Questions\
**Tags:** calculus, graphics-and-visualization, interface-construction, numerical-computation\
**Created:** [January 30, 2022, 9:49am UTC](https://community.wolfram.com/t/plotting-functions-within-a-manipulate/19527 "2022-01-30T09:49:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mishal0488](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@mishal0488](https://community.wolfram.com/u/mishal0488)\
**Post date:** [January 30, 2022, 9:49am UTC](https://community.wolfram.com/t/plotting-functions-within-a-manipulate/19527/1 "2022-01-30T09:49:02Z")

</div>

Hi Guys

Please refer to the attached notebook.  
It is something simple, for a bigger project.  
How do I get the plots to work using Manipulate? The notebook does not run currently with the plotting function.

[Open in Wolfram Cloud ↗](https://www.wolframcloud.com/obj/110543f3-f920-45fb-aba9-e4daf06bc731)

---

<div class="post-metadata">

**Author:** ![hansmilton](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hansmilton/32/8656_2.png) [@hansmilton](https://community.wolfram.com/u/hansmilton)\
**Post date:** [January 30, 2022, 11:39am UTC](https://community.wolfram.com/t/plotting-functions-within-a-manipulate/19527/2 "2022-01-30T11:39:20Z")

</div>

A syntax problem. Your definition of `S` ends with a comma. Replace it with a semicolon.

```
Manipulate[
 	c = 0.1*k*m;
 	F = 1000;
 	S = NDSolve[{m*x''[t] + k*x[t] == F*Sin[w*t], x'[0] == 0, x[0] == 0}, x, {t, 0, 20}];
 	Plot[{x[t], x'[t], x''[t]} /. S, {t, 0, 20}, PlotLegends -> {"x", "y", "Theta"}],
 	{k, 50, 266*1000}, {m, 100, 1000}, {w, 10, 1000}
 ]

```

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [January 30, 2022, 5:07pm UTC](https://community.wolfram.com/t/plotting-functions-within-a-manipulate/19527/3 "2022-01-30T17:07:02Z")

</div>

A part from that, I would insert an `Evaluate` inside `Plot`:

```
Manipulate[c = 0.1*k*m;
 F = 1000;
 S = NDSolve[{m*x''[t] + k*x[t] == F*Sin[w*t], x'[0] == 0, x[0] == 0},
    x, {t, 0, 20}];
 Plot[Evaluate[{x[t], x'[t], x''[t]} /. S], {t, 0, 20}, 
  PlotLegends -> {"x", "y", "Theta"}], {k, 50, 266*1000}, {m, 100, 
  1000}, {w, 10, 1000}]

```

or, even better, use `NDSolveValue`:

```
Manipulate[c = 0.1*k*m;
 F = 1000;
 sol = NDSolveValue[{m*x''[t] + k*x[t] == F*Sin[w*t], x'[0] == 0, 
    x[0] == 0}, x, {t, 0, 20}];
 Plot[{sol[t], sol'[t], sol''[t]}, {t, 0, 20}, 
  PlotLegends -> {"x", "y", "Theta"}], {k, 50, 266*1000}, {m, 100, 
  1000}, {w, 10, 1000}]

```

---

<div class="post-metadata">

**Author:** ![mishal0488](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@mishal0488](https://community.wolfram.com/u/mishal0488)\
**Post date:** [January 30, 2022, 8:05pm UTC](https://community.wolfram.com/t/plotting-functions-within-a-manipulate/19527/4 "2022-01-30T20:05:07Z")

</div>

Thank you kindly
