Message Boards Message Boards

GROUPS:

Plot the result of NDSolve as a RectangleChart3D?

Posted 5 months ago
569 Views
|
4 Replies
|
0 Total Likes
|

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:
4 Replies

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.

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

Posted 3 months 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:

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.

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