Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NDSolve and Parametric Plot

86 views
Skip to first unread message

Alex Cloninger

unread,
Feb 10, 2008, 5:26:41 AM2/10/08
to
So I'm trying to run a simple program that will solve this series of differential equations and plot the the x[t] function in the complex plane. Here's my code.

solution = NDSolve[{x'[t] == 2p[t], x[0] == 2, p'[t] == -2x[t], p[0] == Sqrt[-3]}, {x, p}, {t, 0, 2*π}]

repart[t_] := Re[x[t] /. solution]
impart[t_] := Im[x[t] /. solution]

ParametricPlot[{repart[t], impart[t]}, {t, 0, 2π}, PlotRange -> {{-2, 2}, {-2,2}}]

For some reason, when I go to plot the curve, I get an error saying
ParametricPlot::pptr: {repart[t], impart[t]} does not evaluate to a pair of real numbers at t=2.617993877991494`*^-7

What's going on? Could someone please help me with this?

Bob Hanlon

unread,
Feb 11, 2008, 6:04:48 AM2/11/08
to
Delete the outer braces

solution =
NDSolve[{x'[t] == 2 p[t], x[0] == 2, p'[t] == -2 x[t],
p[0] == Sqrt[-3]}, {x, p}, {t, 0, Pi}][[1]];

repart[t_] := Re[x[t] /. solution]
impart[t_] := Im[x[t] /. solution]

ParametricPlot[{repart[t], impart[t]}, {t, 0, Pi},


PlotRange -> {{-2, 2}, {-2, 2}}]

This can also be solved exactly

solution =
DSolve[{x'[t] == 2 p[t], x[0] == 2, p'[t] == -2 x[t], p[0] ==


= Sqrt[-3]}, {x,

p}, t][[1]]

{x -> Function[{t}, 2*Cos[2*t] + I*Sqrt[3]*Sin[2*t]],
p -> Function[{t}, I*(Sqrt[3]*Cos[2*t] +
2*I*Sin[2*t])]}


Bob Hanlon

---- Alex Cloninger <aclon...@wustl.edu> wrote:
> So I'm trying to run a simple program that will solve this series of diff=
erential equations and plot the the x[t] function in the complex plane. He=
re's my code.
>
> solution = NDSolve[{x'[t] == 2p[t], x[0] == 2, p'[t] == -2x=
[t], p[0] == Sqrt[-3]}, {x, p}, {t, 0, 2*=CF=80}]


>
> repart[t_] := Re[x[t] /. solution]
> impart[t_] := Im[x[t] /. solution]
>

> ParametricPlot[{repart[t], impart[t]}, {t, 0, 2=CF=80}, PlotRange -> {{-2=


, 2}, {-2,2}}]
>
> For some reason, when I go to plot the curve, I get an error saying

> ParametricPlot::pptr: {repart[t], impart[t]} does not evaluate to a pair =

Steve Luttrell

unread,
Feb 11, 2008, 6:09:53 AM2/11/08
to
You need to select the first solution by using [[1]]:

repart[t_] := Re[x[t] /. solution[[1]]]
impart[t_] := Im[x[t] /. solution[[1]]]

Stephen Luttrell
West Malvern, UK

"Alex Cloninger" <aclon...@wustl.edu> wrote in message
news:fomjh1$hmn$1...@smc.vnet.net...


> So I'm trying to run a simple program that will solve this series of
> differential equations and plot the the x[t] function in the complex
> plane. Here's my code.
>
> solution = NDSolve[{x'[t] == 2p[t], x[0] == 2, p'[t] == -2x[t], p[0] ==

> Sqrt[-3]}, {x, p}, {t, 0, 2*Ï?}]


>
> repart[t_] := Re[x[t] /. solution]
> impart[t_] := Im[x[t] /. solution]
>

> ParametricPlot[{repart[t], impart[t]}, {t, 0, 2Ï?}, PlotRange -> {{-2, 2},

janos

unread,
Feb 11, 2008, 6:20:10 AM2/11/08
to
On febr. 10, 11:26, Alex Cloninger <aclonin...@wustl.edu> wrote:
> So I'm trying to run a simple program that will solve this series of diffe=
rential equations and plot the the x[t] function in the complex plane. Here=
's my code.
>
> solution = NDSolve[{x'[t] == 2p[t], x[0] == 2, p'[t] == -2x[=
t], p[0] == Sqrt[-3]}, {x, p}, {t, 0, 2*=F0}]

>
> repart[t_] := Re[x[t] /. solution]
> impart[t_] := Im[x[t] /. solution]
>
> ParametricPlot[{repart[t], impart[t]}, {t, 0, 2=F0}, PlotRange -> {{-2, 2}=

, {-2,2}}]
>
> For some reason, when I go to plot the curve, I get an error saying
> ParametricPlot::pptr: {repart[t], impart[t]} does not evaluate to a pair o=

f real numbers at t=2.617993877991494`*^-7
>
> What's going on? Could someone please help me with this?

Try
ParametricPlot[
Evaluate[{repart[t], impart[t]} /. solution], {t, 0, 2 \[Pi]}]

Hope, it helps,

Janos

Peter Breitfeld

unread,
Feb 11, 2008, 6:26:16 AM2/11/08
to
Alex Cloninger schrieb:

You should write:
repart:=Re[ x[t]/.solution[[1]] ]
impart:=Im[ x[t]/.solution[[1]] ]

ParametricPlot[{repart,impart},{t,0,2Pi}]

Gruss Peter
--
==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de

Jens-Peer Kuska

unread,
Feb 11, 2008, 6:28:18 AM2/11/08
to
Hi,

solution =
NDSolve[{x'[t] == 2 p[t], x[0] == 2, p'[t] == -2 x[t],
p[0] == Sqrt[-3]}, {x[t], p[t]}, {t, 0, 2*Pi}];

repart[tau_] := (Re[x[t] /. solution[[1]]] ) /. t -> tau
impart[tau_] := (Im[x[t] /. solution[[1]]] ) /. t -> tau

ParametricPlot[{repart[t], impart[t]}, {t, 0, 2 Pi},


PlotRange -> {{-2, 2}, {-2, 2}}]

may help.

Regards
Jens

Alex Cloninger wrote:
> So I'm trying to run a simple program that will solve this series of di=
fferential equations and plot the the x[t] function in the complex plane.=
Here's my code.
>
> solution = NDSolve[{x'[t] == 2p[t], x[0] == 2, p'[t] == -=
2x[t], p[0] == Sqrt[-3]}, {x, p}, {t, 0, 2*=CF=80}]


>
> repart[t_] := Re[x[t] /. solution]
> impart[t_] := Im[x[t] /. solution]
>

> ParametricPlot[{repart[t], impart[t]}, {t, 0, 2=CF=80}, PlotRange -> {{=


-2, 2}, {-2,2}}]
>
> For some reason, when I go to plot the curve, I get an error saying

> ParametricPlot::pptr: {repart[t], impart[t]} does not evaluate to a pai=

0 new messages