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

Phase Plot of Simple Harmonic Motion using Mathematica ??

209 views
Skip to first unread message

Rahul Chakraborty

unread,
May 15, 2012, 4:56:13 AM5/15/12
to
Hi all,

Plz check my code below for Phase plot of Simple Harmonic motion. The output should be a circle with x along X-axis and dxdt along y-axis.

I'm not getting the output. kindly let me know where i'm wrong.

Clear[k, m];
k = 1;
m = 3;
solution =
NDSolve[{x''[t] + k/m x[t] == 0, x[0] == 5, x'[0] == 0},
x, {t, 0, 250}, MaxSteps \[RightArrow] 50000,
WorkingPrecision \[RightArrow] 25]
ParametricPlot[Evaluate[{x[t], x'[t]} /. solution], {t, 0, 100},
PlotRange \[RightArrow] All,
AxesLabel -> {"x", "\!\(\*OverscriptBox[\(x\), \(.\)]\)"}]


Following are the errors:

1)NDSolve::dvlen: The function x[t] does not have the same number of arguments as independent variables (3). >>

2)ReplaceAll::reps: {NDSolve[{x[t]/3+(x^\[Prime]\[Prime])[t]==0,x[0]==5,(x^\[Prime])[0]==0},x,{t,0,250},MaxSteps\[RightArrow]50000,WorkingPrecision\[RightArrow]25]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>

3)ParametricPlot::pllim: Range specification PlotRange\[RightArrow]All is not of the form {x, xmin, xmax}. >>


Regards,

rc

Nasser M. Abbasi

unread,
May 16, 2012, 4:26:23 AM5/16/12
to
On 5/15/2012 3:56 AM, Rahul Chakraborty wrote:
> Hi all,
>
> Plz check my code below for Phase plot of Simple Harmonic motion. The output should be a circle with x along X-axis and dxdt along y-axis.
>
> I'm not getting the output. kindly let me know where i'm wrong.
>
> Clear[k, m];
> k = 1;
> m = 3;
> solution =
> NDSolve[{x''[t] + k/m x[t] == 0, x[0] == 5, x'[0] == 0},
> x, {t, 0, 250}, MaxSteps \[RightArrow] 50000,
> WorkingPrecision \[RightArrow] 25]
>
>
> Following are the errors:
>

This works for me. Just changed your \[RightArrow] with normal
ascii ->

NDSolve[{x''[t] + (k/m)*x[t] == 0, x[0] == 5,
x'[0] == 0}, x, {t, 0, 250}, MaxSteps -> 50000,
WorkingPrecision -> 25]

--Nasser

DC

unread,
May 16, 2012, 4:23:19 AM5/16/12
to
I would change the definition of solution so it's a simple function of t, then you'd take its derivative/do the plot in the usual way.

solution[t_] =
NDSolve[{x''[t] + k/m x[t] == 0, x[0] == 5, x'[0] == 0},
x[t], {t, 0, 250}][[1, 1, 2]]
ParametricPlot[{solution[t], solution'[t]}, {t, 0, 100}]

Bob Hanlon

unread,
May 16, 2012, 4:24:20 AM5/16/12
to
When I copied and pasted your input I had the same error. However,
after I manually re-entered the line defining solution all worked
well. You must have some invisible character in your input.


Bob Hanlon


On Tue, May 15, 2012 at 4:54 AM, Rahul Chakraborty
<rahul...@gmail.com> wrote:
> Hi all,
>
> Plz check my code below for Phase plot of Simple Harmonic motion. The =
output should be a circle with x along X-axis and dxdt along y-axis.
>
> I'm not getting the output. kindly let me know where i'm wrong.
>
> Clear[k, m];
> k = 1;
> m = 3;
> solution =
> NDSolve[{x''[t] + k/m x[t] == 0, x[0] == 5, x'[0] == 0},
> x, {t, 0, 250}, MaxSteps \[RightArrow] 50000,
> WorkingPrecision \[RightArrow] 25]
> ParametricPlot[Evaluate[{x[t], x'[t]} /. solution], {t, 0, 100},
> PlotRange \[RightArrow] All,
> AxesLabel -> {"x", "\!\(\*OverscriptBox[\(x\), \(.\)]\)"}]
>
>
> Following are the errors:
>
> 1)NDSolve::dvlen: The function x[t] does not have the same number of argu=
ments as independent variables (3). >>
>
> 2)ReplaceAll::reps: {NDSolve[{x[t]/3+(x^\[Prime]\[Prime])[t]==0,x[0]=
==5,(x^\[Prime])[0]==0},x,{t,0,250},MaxSteps\[RightArrow]50000,Work=
ingPrecision\[RightArrow]25]} is neither a list of replacement rules nor a =
valid dispatch table, and so cannot be used for replacing. >>
>
> 3)ParametricPlot::pllim: Range specification PlotRange\[RightArrow]All is=
not of the form {x, xmin, xmax}. >>
>
>
> Regards,
>
> rc
>



--
Bob Hanlon

Christoph Lhotka

unread,
May 16, 2012, 4:25:22 AM5/16/12
to
Dear Rahul,

this makes your code work:

replace in your expression \[RightArrow] by \[Rule] (delete the arrows
and retype them properly).

If you look on the documentation for \[RightArrow]
you will find that it has no built-in meaning and that it can be entered
as [ESC]_->[ESC], where _ stands for an extra space, while \[Rule] is
entered as [ESC]->[ESC] only.

In the email text it is easy to see the difference between \[RightArrow]
and \[Rule], to
see the difference in your notebook just press Shift+Ctrl+E inside the
cell or use
Hold[expr]//FullForm to see the unevaluated fullform of the expression.

Best,

Christoph

Addendum: another issue is, that the error messages of the present
example are not really
related to the problem, does anyone know why?




On 05/15/2012 10:54 AM, Rahul Chakraborty wrote:
> Hi all,
>
> Plz check my code below for Phase plot of Simple Harmonic motion. The output should be a circle with x along X-axis and dxdt along y-axis.
>
> I'm not getting the output. kindly let me know where i'm wrong.
>
> Clear[k, m];
> k = 1;
> m = 3;
> solution =
> NDSolve[{x''[t] + k/m x[t] == 0, x[0] == 5, x'[0] == 0},
> x, {t, 0, 250}, MaxSteps \[RightArrow] 50000,
> WorkingPrecision \[RightArrow] 25]
> ParametricPlot[Evaluate[{x[t], x'[t]} /. solution], {t, 0, 100},
> PlotRange \[RightArrow] All,
> AxesLabel -> {"x", "\!\(\*OverscriptBox[\(x\), \(.\)]\)"}]
>
>
> Following are the errors:
>
> 1)NDSolve::dvlen: The function x[t] does not have the same number of arguments as independent variables (3).>>
>
> 2)ReplaceAll::reps: {NDSolve[{x[t]/3+(x^\[Prime]\[Prime])[t]==0,x[0]==5,(x^\[Prime])[0]==0},x,{t,0,250},MaxSteps\[RightArrow]50000,WorkingPrecision\[RightArrow]25]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.>>
>
> 3)ParametricPlot::pllim: Range specification PlotRange\[RightArrow]All is not of the form {x, xmin, xmax}.>>
>
>
> Regards,
>
> rc
>


Alexei Boulbitch

unread,
May 17, 2012, 4:07:51 AM5/17/12
to
Hi all,

Plz check my code below for Phase plot of Simple Harmonic motion. The output should be a circle with x along X-axis and dxdt along y-axis.

I'm not getting the output. kindly let me know where i'm wrong.

Clear[k, m];
k = 1;
m = 3;
solution =
NDSolve[{x''[t] + k/m x[t] == 0, x[0] == 5, x'[0] == 0},
x, {t, 0, 250}, MaxSteps \[RightArrow] 50000,
WorkingPrecision \[RightArrow] 25]
ParametricPlot[Evaluate[{x[t], x'[t]} /. solution], {t, 0, 100},
PlotRange \[RightArrow] All,
AxesLabel -> {"x", "\!\(\*OverscriptBox[\(x\), \(.\)]\)"}]

Regards, Rc

Hi, Rahul,

Try this:

Clear[k, m];
k = 1;
m = 3;
solution =
NDSolve[{x''[t] + (k/m )*x[t] == 0, x[0] == 5, x'[0] == 0},
x, {t, 0, 250}] // Flatten
ParametricPlot[Evaluate[{x[t], x'[t]} /. solution], {t, 0, 100},
AxesLabel -> {"x", "x'"}, PlotRange -> All]

The main difference in the function Flatten that I apply to the solution. I t removes the extra parentheses. The latter have prevented you from getting solution.

Have fun, Alexei

Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone : +352-2454-2566
Office fax: +352-2454-3566
mobile phone: +49 151 52 40 66 44

e-mail: alexei.b...@iee.lu




0 new messages