Group Abstract Group Abstract

Message Boards Message Boards

Parametric plot for NDSolve output

Posted 10 years ago

I am practicing with a non-linear differential equation and attempting to get a parametric plot of the solution at different times. The ParametricPlot function works fine for a display of the output for a continuous range of t, but I need a plot that shows the output at a sequence of times. The equation is:

s = NDSolve[{\[CapitalTheta]''[t] + Sin[\[CapitalTheta][t]] == 0, \[CapitalTheta][0] == \[Pi]/2, \[CapitalTheta]'[0] == 
1.4141999}, \[CapitalTheta], {t, 0, 100}]
theta[t_] := \[CapitalTheta][t] /. s
thetaprime[t_] := \[CapitalTheta]'[t] /. s
Plot[theta[t], {t, 0, 100}]
Table[theta[t], {t, 0, 100, 0.5}];
ListPlot[%]
Table[thetaprime[t], {t, 0, 100, 0.5}];
ListPlot[%]
(*Table[theta[t],thetaprime[t], {t, 0, 500, 100}]
ListPlot[%]*)
![enter image description here][1]

So, I have two issues with this:

1) the ListPlot[%] shows all the values of theta at 1 -- I would expect the x-axis to display the value of t.

2) when I try to generate a 2-D table of values (theta[t] and thetaprime[t]), I get syntax errors.

Many years ago I was pretty good at Mathematica (version 3.0!) -- I seem to have lost it and need help with managing lists and tables.

POSTED BY: Steve Bardwell
2 Replies
Posted 10 years ago

Wonderful. This is now doing what I need. I may have to get a new Mathematica manual -- the 4.0 manual doesn't have NDSolveValue ! Thanks for taking the time to answer a pretty lame question.

POSTED BY: Steve Bardwell

The first problem is that NDSolve gives a List as a result. Your table of values is a list of lists, which is not what you want. Moreover, ListPlot cannot know what the values of t are, and it assumes that they are consecutive integers. Try this way:

theta = NDSolveValue[{\[CapitalTheta]''[t] + 
      Sin[\[CapitalTheta][t]] == 
     0, \[CapitalTheta][0] == \[Pi]/2, \[CapitalTheta]'[0] == 
     1.4141999}, \[CapitalTheta], {t, 0, 100}];
thetaprime = theta'; 
Plot[theta[t], {t, 0, 100}]
Table[{t, theta[t]}, {t, 0, 100, 0.5}];
ListPlot[%] 
Table[{t, thetaprime[t]}, {t, 0, 100, 0.5}];
ListPlot[%] 
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard