Message Boards Message Boards

Plot the result of NDSolve as a RectangleChart3D?

Posted 6 years ago

Hi, I request a solution to my problem where i want to plot the either the energy (x^2) or the signal itself (x) which is being the solution of a differential solution. I am successful only placing the phase-plane of a 2D system but the bar graph on the right does not shown anything. The code is

splot = StreamPlot[{y, -Sin[x] - .25 y}, {x, -4, 4}, {y, -3, 3}];
Manipulate[
 Grid[{{Show[splot, 
     ParametricPlot[
      Evaluate[
       First[{x[t], y[t]} /. 
         NDSolve[{x'[t] == y[t], y'[t] == -Sin[x[t]] - .25 y[t], 
           Thread[{x[0], y[0]} == point]}, {x, y}, {t, 0, T}]]], {t, 
       0, T}, PlotStyle -> Red]], 
    RectangleChart3D[{{0.25, 1, 
       Evaluate[
        First[{x[t]} /. 
          NDSolve[{x'[t] == y[t], y'[t] == -Sin[x[t]] - .25 y[t], 
            Thread[{x[0], y[0]} == point]}, {x, y}, {t, 0, 
            T}]]]}, {0.25, 1, 
       Evaluate[
        First[{y[t]} /. 
          NDSolve[{x'[t] == y[t], y'[t] == -Sin[x[t]] - .25 y[t], 
            Thread[{x[0], y[0]} == point]}, {x, y}, {t, 0, T}]]]}}, 
     ChartLegends -> {"x[t]", "y[t]"}, PlotRange -> {0, 1}, 
     ImageSize -> {200, 250}, ChartStyle -> {Red, Green}, 
     AspectRatio -> 1, BarSpacing -> 0.2, Axes -> False]}}], {{T, 90},
   1, 100}, {{point, {2, 1.0}}, Locator}, SaveDefinitions -> True]
Attachments:
POSTED BY: Salman Zaffar
4 Replies
Posted 6 years ago

Thanks for your reply,

What if instead of plotting the states x(t) and y(t) as two separate bars, i wish to plot a single bar with third dimension a function of these two states as shown in the attached snap. please help.

Attachment

Attachments:
POSTED BY: Salman Zaffar

What did you try? This is

Manipulate[
 Grid[{{Show[splot, 
     ParametricPlot[
      Evaluate[
       First[{x[t], y[t]} /. 
         NDSolve[{x'[t] == y[t], y'[t] == -Sin[x[t]] - .25 y[t], 
           Thread[{x[0], y[0]} == point]}, {x, y}, {t, 0, T}]]], {t, 
       0, T}, PlotStyle -> Red]],
    RectangleChart3D[{{0.25, 1, 
       NIntegrate[
        Dot[#, #] &[
         Evaluate[
           First[{x[t], y[t]} /. 
             NDSolve[{x'[t] == y[t], y'[t] == -Sin[x[t]] - .25 y[t], 
               Thread[{x[0], y[0]} == point]}, {x, y}, {t, 0, 
               T}]]] //. t -> q], {q, 0, T}]}}, 
     ChartLegends -> {"E[T]"}, ImageSize -> {200, 250}, 
     ChartStyle -> {Red}, AspectRatio -> 1, BarSpacing -> 0.2, 
     Axes -> True]}}], {{T, 90}, 1, 100}, {{point, {2, 1.0}}, 
  Locator}, SaveDefinitions -> True]

and a picture is

enter image description here

don't miss to skip the PlotRange -> {0,1} option.

POSTED BY: Dent de Lion
Posted 6 years ago

I need a little more help in this...how is it possible?

POSTED BY: Updating Name

Try this

Manipulate[
 Grid[{{Show[splot, 
     ParametricPlot[
      Evaluate[
       First[{x[t], y[t]} /. 
         NDSolve[{x'[t] == y[t], y'[t] == -Sin[x[t]] - .25 y[t], 
           Thread[{x[0], y[0]} == point]}, {x, y}, {t, 0, T}]]], {t, 
       0, T}, PlotStyle -> Red]],
    RectangleChart3D[{{0.25, 1, #} & /@ 
       Evaluate[
        First[{x[t], y[t]} /. 
           NDSolve[{x'[t] == y[t], y'[t] == -Sin[x[t]] - .25 y[t], 
             Thread[{x[0], y[0]} == point]}, {x, y}, {t, 0, T}]] /. 
         t -> T]}, ChartLegends -> {"x[t]", "y[t]"}, 
     PlotRange -> {0, 1}, ImageSize -> {200, 250}, 
     ChartStyle -> {Red, Green}, AspectRatio -> 1, BarSpacing -> 0.2, 
     Axes -> True]}}], {{T, 90}, 1, 100}, {{point, {2, 1.0}}, 
  Locator}, SaveDefinitions -> True]

because it's working

enter image description here

keep in mind InterpolationFunction[] objects need an argument to show it's values, use mapping to avoid to solve the ODE more often than needed.

POSTED BY: Dent de Lion
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract