# Function output used in Graphics\[\]....

**URL:** <https://community.wolfram.com/t/function-output-used-in-graphics/4576>\
**Category:** Questions\
**Tags:** mathematica, equation-solving, graphics-and-visualization\
**Created:** [January 20, 2015, 10:47pm UTC](https://community.wolfram.com/t/function-output-used-in-graphics/4576 "2015-01-20T22:47:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirktim](https://avatars.discourse-cdn.com/v4/letter/k/a9a28c/32.png) [@kirktim](https://community.wolfram.com/u/kirktim)\
**Post date:** [January 20, 2015, 10:47pm UTC](https://community.wolfram.com/t/function-output-used-in-graphics/4576/1 "2015-01-20T22:47:45Z")

</div>

I’m trying to plot the output of an equation in Graphics. However, Graphics does not appear to recognize the output; only explicitly writing the function into Graphics will work (see code below). Does anyone know a workaround for this?

```
Eqn1 = D[f[t], {t, 2}] + \[Omega]^2*f[t] == 0;

IC1 = f[0] == \[Alpha];

IC2 = (D[f[t], {t, 1}] == \[Gamma]) /. { t -> 0 };

Sol2 = Simplify[DSolve[{Eqn1, IC1, IC2}, f[t], t] ];

x[\[Alpha]_, \[Gamma]_, \[Omega]_, t_] = Replace[f[t], Sol2 ];

Manipulate[
  
  Graphics[{
    
    (* Frame *)
    {  
     Directive[AbsoluteThickness[5], RGBColor[0.25, 0.25, 0.25]],
     Line[{{-25, 0}, {50, 0}}],
     Line[{{-25, 0}, {-25, 15}}]
     },
    
    {
     RGBColor[0.25, 0.25, 0.75],
     AbsoluteThickness[2.5],
     Dashed, Line[{{0, 0}, {0, 15}}]
     },
    
    (* x(t) = 0 *)
    {  
     Inset[Style["x(t) = 0", 20, FontFamily -> "Times"], {0, -5}]  
     },
    
    (* Oscillating Masses *)
    {  
     RGBColor[0, 0, 0.75],
     EdgeForm[
      Directive[AbsoluteThickness[2.5], Dashed, RGBColor[0, 0, 0]]],
     Rectangle[{ (x[\[Alpha], \[Gamma], \[Omega], tmax]) + 5 , 
       0 }, { (x[\[Alpha], \[Gamma], \[Omega], tmax]) - 5 , 10 } ]
     },
    
    (* The Spring *)
    {
     ParametricPlot[ {  
        sex/(
          2 \[Pi])*((x[\[Alpha], \[Gamma], \[Omega], tmax]) + 25) - 
         25, 5 + 2.25*Sin[10*sex] },
       
       {sex, 0, 2 \[Pi]},
       
       PlotStyle -> {
         Directive[RGBColor[0, 0, 0], AbsoluteThickness[2.5]]
         },
       
       Axes -> None][[1]]
     }
    
    (* Graphics *)}],
  
  Style["", Bold, 14, FontFamily -> "Times"],
  {{\[Alpha], -10, Style["\[Alpha]", 16, FontFamily -> "Times"]}, -10,
    10, 0.01, ImageSize -> Medium, Appearance -> "Labeled"},

  Style["", Bold, 14, FontFamily -> "Times"],
  {{\[Gamma], 0, Style["\[Gamma]", 16, FontFamily -> "Times"]}, -10, 
   10, 0.01, ImageSize -> Medium, Appearance -> "Labeled"},

  Style["", Bold, 14, FontFamily -> "Times"],
  {{\[Omega], 1.0, 
    Style["\[Omega] [rad. \!\(\*SuperscriptBox[\(s\), \(-1\)]\)]", 16,
      FontFamily -> "Times"]}, 0, 10, 0.01, ImageSize -> Medium, 
   Appearance -> "Labeled"},

  Style["Axis Parameters", Underlined, 14, FontFamily -> "Times"],
  {{tmax, 10^-20, Style["time", 16, FontFamily -> "Times"]}, 10^-20, 
   120, ControlType -> Trigger, DefaultDuration -> 120.0, 
   DisplayAllSteps -> True, AnimationRate -> 1.0, ImageSize -> Medium,
    Appearance -> "Labeled"},
  
  ControlPlacement -> Left,
  SaveDefinitions -> False,
  TrackedSymbols :> {\[Alpha], \[Gamma], \[Omega], tmax}
  
  (* Manipulate *)]

However, writing the function directly into Graphics does work.

Manipulate[
  
  Graphics[{
    
    (* Frame *)
    {  
     Directive[AbsoluteThickness[5], RGBColor[0.25, 0.25, 0.25]],
     Line[{{-25, 0}, {50, 0}}],
     Line[{{-25, 0}, {-25, 15}}]
     },
    
    {
     RGBColor[0.25, 0.25, 0.75],
     AbsoluteThickness[2.5],
     Dashed, Line[{{0, 0}, {0, 15}}]
     },
    
    (* x(t) = 0 *)
    {  
     Inset[Style["x(t) = 0", 20, FontFamily -> "Times"], {0, -5}]  
     },
    
    (* Oscillating Masses *)
    {  
     RGBColor[0, 0, 0.75],
     EdgeForm[
      Directive[AbsoluteThickness[2.5], Dashed, RGBColor[0, 0, 0]]],
     Rectangle[{ (\[Alpha] Cos[tmax \[Omega]] + (\[Gamma] Sin[
            tmax \[Omega]])/\[Omega]) + 5 , 
       0 }, { (\[Alpha] Cos[tmax \[Omega]] + (\[Gamma] Sin[
            tmax \[Omega]])/\[Omega]) - 5 , 10 } ]
     },
    
    (* The Spring *)
    {
     ParametricPlot[ {  
        sex/(2 \[Pi])*((\[Alpha] Cos[tmax \[Omega]] + (\[Gamma] Sin[
                tmax \[Omega]])/\[Omega]) + 25) - 25, 
        5 + 2.25*Sin[10*sex] },
       
       {sex, 0, 2 \[Pi]},
       
       PlotStyle -> {
         Directive[RGBColor[0, 0, 0], AbsoluteThickness[2.5]]
         },
       
       Axes -> None][[1]]
     }
    
    (* Graphics *)}],
  
  Style["", Bold, 14, FontFamily -> "Times"],
  {{\[Alpha], -10, Style["\[Alpha]", 16, FontFamily -> "Times"]}, -10,
    10, 0.01, ImageSize -> Medium, Appearance -> "Labeled"},

  Style["", Bold, 14, FontFamily -> "Times"],
  {{\[Gamma], 0, Style["\[Gamma]", 16, FontFamily -> "Times"]}, -10, 
   10, 0.01, ImageSize -> Medium, Appearance -> "Labeled"},

  Style["", Bold, 14, FontFamily -> "Times"],
  {{\[Omega], 1.0, 
    Style["\[Omega] [rad. \!\(\*SuperscriptBox[\(s\), \(-1\)]\)]", 16,
      FontFamily -> "Times"]}, 0, 10, 0.01, ImageSize -> Medium, 
   Appearance -> "Labeled"},

  Style["Axis Parameters", Underlined, 14, FontFamily -> "Times"],
  {{tmax, 10^-20, Style["time", 16, FontFamily -> "Times"]}, 10^-20, 
   120, ControlType -> Trigger, DefaultDuration -> 120.0, 
   DisplayAllSteps -> True, AnimationRate -> 1.0, ImageSize -> Medium,
    Appearance -> "Labeled"},
  
  ControlPlacement -> Left,
  SaveDefinitions -> False,
  TrackedSymbols :> {\[Alpha], \[Gamma], \[Omega], tmax}
  
  (* Manipulate *)]

```

Any suggestions for using the output in Graphics?

---

<div class="post-metadata">

**Author:** ![fkampas](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/fkampas/32/41217_2.png) [@fkampas](https://community.wolfram.com/u/fkampas)\
**Post date:** [January 21, 2015, 10:47pm UTC](https://community.wolfram.com/t/function-output-used-in-graphics/4576/2 "2015-01-21T22:47:15Z")

</div>

It would be easier to help you if you can generate a simpler example of this problem.

---

<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 22, 2015, 10:27am UTC](https://community.wolfram.com/t/function-output-used-in-graphics/4576/3 "2015-01-22T10:27:33Z")

</div>

Actually, on my system it is the first version (with functions on the outside) that does not work, but it is easy to fix: just write

```
Sol2 = Simplify[First@DSolve[{Eqn1, IC1, IC2}, f[t], t]]

```

instead of

```
Sol2 = Simplify[DSolve[{Eqn1, IC1, IC2}, f[t], t]]

```

A part from this, they both show an oscillating mass attached to a spring. At first sight I can’t detect a difference or anything wrong.

---

<div class="post-metadata">

**Author:** ![kirktim](https://avatars.discourse-cdn.com/v4/letter/k/a9a28c/32.png) [@kirktim](https://community.wolfram.com/u/kirktim)\
**Post date:** [January 22, 2015, 3:51pm UTC](https://community.wolfram.com/t/function-output-used-in-graphics/4576/4 "2015-01-22T15:51:15Z")

</div>

Yes, that fixed it! Thank you. What does the “First@” in front of DSolve do?

---

<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 22, 2015, 4:07pm UTC](https://community.wolfram.com/t/function-output-used-in-graphics/4576/5 "2015-01-22T16:07:32Z")

</div>

It removes the extra pair of brackets {} that encloses the solutions. With those brackets the x[] becomes of the form {number}, which messes up the coordinates in

```
 Rectangle[{ (x[...]) + 5 , 
       0 }, { (x[...]) - 5 , 10 } ]

```

In general, DSolve gives solutions in the form `{{solution}}`. In your case you only want `{solution}`.

---

<div class="post-metadata">

**Author:** ![kirktim](https://avatars.discourse-cdn.com/v4/letter/k/a9a28c/32.png) [@kirktim](https://community.wolfram.com/u/kirktim)\
**Post date:** [January 22, 2015, 4:16pm UTC](https://community.wolfram.com/t/function-output-used-in-graphics/4576/6 "2015-01-22T16:16:32Z")

</div>

Thank you.
