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

How to rectify the error for NDSolve ?

1,070 views
Skip to first unread message

Rahul Chakraborty

unread,
Jun 29, 2012, 4:54:10 AM6/29/12
to
Dear all,

Plz let me know as how should i rectify the error:

NDSolve::dsvar: 5 cannot be used as a variable.

I tried the suggestion in help using
clear[x], but still my code not giving result.

Needs suggestion.

Regards,
rahul

Nasser M. Abbasi

unread,
Jun 30, 2012, 5:16:18 AM6/30/12
to
Need to see what you wrote

--Nasser



Helen Read

unread,
Jul 1, 2012, 2:07:52 AM7/1/12
to
I'm surprised not see 10 responses to this, but maybe everyone else
figured someone else would answer it and let it go (as I did when I saw
it yesterday). Anyway, if you really wrote it as clear[x] that's your
problem right there. Remember that all built-in functions begin with a
capital letter.

Clear[x]

Helen Read
University of Vermont

Rahul Chakraborty

unread,
Jul 1, 2012, 2:15:00 AM7/1/12
to
Here is my code:


clear[x, t, \[Tau], Q, Subscript[V, p], Subscript[V,
1], \[CapitalGamma], \[Phi]];
Q = 100;
\[CapitalGamma] = 50;
Subscript[\[Omega], 0] = 10;
Subscript[V, p] = 0.5;
Subscript[C, 0] = 4.06 * 10^-4;
t = 5;
\[Tau] = Subscript[\[Omega], 0] t;
\[Phi] = 90;
Subscript[V, 1] = Subscript[C, 0]*Subscript[V, p];
eqn = x'' (\[Tau]) +
1/Q x' (\[Tau]) + (1 +
Subscript[V, 1] Sqrt[2]
Sin[2 \[Tau]]) x == \[CapitalGamma] (sin[\[Tau] + \[Phi]]);
sol = NDSolve[{eqn, x[0] == 0.5, x'[0] == 0}, x, {t, 0, 250},
MaxSteps -> 500000, WorkingPrecision -> 25][[1]]
ParametricPlot[Evaluate[{x[t], x'[t]} /. sol], {t, 0, 100},
Frame -> True, PlotRange -> All,
AxesLabel -> {"t", "\!\(\*OverscriptBox[\(\[Theta]\), \(.\)]\)"}]


Output i'm getting is as below:

NDSolve::dsvar: 5 cannot be used as a variable. >>


{0.999855 x + Derivative[1][x]/2 + 50 x^\[Prime]\[Prime] ==
50 sin[140], x[0] == 0.5, Derivative[1][x][0] == 0}


ReplaceAll::reps: {0.999855 x+x^\[Prime]/2+50 x^\[Prime]\[Prime]==50 sin[140],x[0]==0.5,(x^\[Prime])[0]==0} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>


ReplaceAll::reps: {0.999855 x+0.5 x^\[Prime]+50. x^\[Prime]\[Prime]==50. sin[140.],x[0.]==0.5,(x^\[Prime])[0.]==0.} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>

ReplaceAll::reps: {0.999855 x+0.5 x^\[Prime]+50. x^\[Prime]\[Prime]==50. sin[140.],x[0.]==0.5,(x^\[Prime])[0.]==0.} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>

General::stop: Further output of ReplaceAll::reps will be suppressed during this calculation. >>


Regards,

rahul

Murray Eisenberg

unread,
Jul 2, 2012, 5:32:23 AM7/2/12
to
So many errors in your code!

(1) As somebody already noted in a reply to your earlier post (before
you showed any code), you forgot to use an uppercase letter in Clear.

And you also forgot to use an uppercase letter in the sine expression on
the right-hand side of the differential equation.

(2) The root cause of the error message you received is because first
you set t = 5 and then a multiple of that; now t is a constant! But then
you use the _same_ symbol t as if it were the variable in your
differential equation. Change either the constant t to some other name
or the variable t in your differential equation et seq. to some other name.

(3) You are not using correct syntax in the definition of eqn: all
function arguments should be enclosed in brackets, not parentheses. And
you forgot to include the argument of t for x at the end of the
left-hand side of the equation. Thus you seem to want:

eqn = x''[\[Tau]] +1/Q x'[\[Tau]] +
(1+Subscript[V,1] Sqrt[2] Sin[2 \[Tau]]) x[t]
==\[CapitalGamma] (Sin[\[Tau]+\[Phi]]);

Note that I removed the parentheses in the right-hand side, as there's
no reason to have them.

(4) Remove Subscript[V,p] and Subscript[V,1] from the Clear expression,
as they are not Symbols (or Strings). If they don't already have values,
you don't need to get "clear" them in any sense. If they do, you have to
use Unset:

Unset[Subscript[V,p]]
Unset[Subscript[V,1]]

(You can Unset several things at once by using Map.)

(5) After all that, at this point I do not understand your differential
equation -- I don't know what you really intend the value of \[Tau] to
be. You had set t = 5, so that after

\[Tau] = Subscript[\[Omega], 0] t;

\[Tau] is also a constant, as is, therefore, the right-hand side of your
differential equation. I suspect that's NOT what you intended.

In fact, I don't understand at all why you even set t to be a constant.

But if you simply fix all the things indicated above and omit the
assignment t = 5, I think Mathematica will not be able to deal with this
differential equation.

However, if you change the term that involving what I said should be
x[t] in place of just x to have variable \[Tau] instead of t -- is that
what you actually intended?? -- I think Mathematica will still balk at
providing a solution.

If, though, you make a change of variable from t to tt ....

neweqn = eqn /. t -> tt/10

... then the following _will_ provide a numerical solution:

NDSolve[{neweqn, x[0] == 0.5, x'[0] == 0}, x[tt], {tt, 0, 250}]

P.S. By any chance, did you retype your code when writing your e-mail
post? If so, that in itself may have introduced errors. You should use
Mathematica's menu selection Edit > Copy As Plain Text to copy, then
past into your message.
--
Murray Eisenberg mur...@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305

Rahul Chakraborty

unread,
Jul 2, 2012, 10:19:57 PM7/2/12
to
Dear all,

Thanks to Murray for your reply. I have made changes as per advice but still no result. The differential eqn is also changed to make it simpler.

Here is my code:

Clear[x,\[Tau],Q,\[CapitalGamma],\[Phi]];
Q=100;
\[CapitalGamma]=50;
Subscript[\[Omega], 0]=10;
Subscript[V, p]=0.5;
Subscript[C, 0]=4.06 * 10^-4;
\[Phi]=90;
Subscript[V, 1](t)=Sqrt[2] Subscript[V, p]Sin(2Subscript[\[Omega], 0]t);
eqn= x''[t]+Subscript[\[Omega], 0]/Q x'[t]+Subscript[(\[Omega]^2), 0][1+Subscript[c, 0] Subscript[V, 1](t)]x[t]==\[CapitalGamma]Sin[Subscript[\[Omega], 0]t+\[Phi]];
sol=NDSolve[{eqn,x[0]==0.5,x'[0]==0},x[t],{t,0,250},MaxSteps-> 500000,WorkingPrecision-> 25][[1]]
ParametricPlot[Evaluate[{x[t],x'[t]}/.sol],{t,0,100},Frame->True,PlotRange-> All,AxesLabel-> {"t","Overscript[\[Theta], .]"}]

Regards,
rc

Bob Hanlon

unread,
Jul 4, 2012, 3:31:01 AM7/4/12
to
You still have multiple syntax errors.

If you are going to specify a working precision, all input numbers
must be at least that precision. For example, 0.5 must be either exact
(i.e., 1/2) or high precision (e.g., 0.5`25).

I shortened the interval since the plot is too dense for wider ranges.

Clear[x, \[Tau], Q, \[CapitalGamma], \[Phi], V, t];
Q = 100;
\[CapitalGamma] = 50;
Subscript[\[Omega], 0] = 10;
Subscript[V, p] = 1/2;
Subscript[c, 0] = 406*10^-6;
\[Phi] = 90;
Subscript[V, 1][t] =
Sqrt[2] Subscript[V, p] Sin[2 Subscript[\[Omega], 0] t];

eqn = x''[t] + Subscript[\[Omega], 0]/Q x'[t] +
Subscript[\[Omega], 0]^2*
(1 + Subscript[c, 0] Subscript[V, 1][t]) x[
t] ==
\[CapitalGamma] Sin[Subscript[\[Omega], 0] t + \[Phi]] //
Simplify;

sol = NDSolve[{eqn, x[0] == 1/2, x'[0] == 0},
x[t], {t, 0, 25}][[1]];

ParametricPlot[Evaluate[
{x[t] /. sol, D[x[t] /. sol, t]}],
{t, 0, 25},
Frame -> True,
AxesLabel -> {"t", Overscript[\[Theta], "."]},
AspectRatio -> 1]


Bb Hanlon

Rahul Chakraborty

unread,
Jul 5, 2012, 6:12:50 AM7/5/12
to
Following is the code as modified:

Clear[x,Q,\[CapitalGamma],\[Phi]];
Q=100;
\[CapitalGamma]=50;
Subscript[\[Omega], 0]=10;
Subscript[V, p]=1/2;
Subscript[C, 0]=406 * 10^-6;
\[Phi]=90;
\[Gamma]=1/Q;
Subscript[V, 1][t]=Sqrt[2] Subscript[V, p]Sin[2Subscript[\[Omega], 0]t];
eqn= x''[t]+Subscript[\[Gamma]\[Omega], 0]x'[t]+(Subscript[\[Omega], 0]^2)[1+Subscript[c, 0]Subscript[V, 1][t]]x[t]-\[CapitalGamma] Sin[Subscript[\[Omega], 0]t+\[Phi]]==0//Simplify;
sol=NDSolve[{eqn,x[0]==1/2,x'[0]==0},x[t],{t,0,25}][[1]]
ParametricPlot[Evaluate[{x[t]/.sol,D[x[t]/.sol,t]}],{t,0,25},Frame->True,AxesLabel->{"t",Overscript[\[Theta],"."]},AspectRatio->1]


ERROR showing as follows:

NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.`. >>

Plz advice me how to correct this error.

Regards,

rc

Rahul Chakraborty

unread,
Jul 5, 2012, 6:13:20 AM7/5/12
to
I have made the changes as suggested by Bob but still some errors are there:

Clear[x,Q,\[CapitalGamma],\[Phi]];
Q=100;
\[CapitalGamma]=50;
Subscript[\[Omega], 0]=10;
Subscript[V, p]=1/2;
Subscript[C, 0]=406 * 10^-6;
\[Phi]=90;
Subscript[V, 1][t]=Sqrt[2] Subscript[V, p]Sin[2Subscript[\[Omega], 0]t];
eqn= x''[t]+Subscript[\[Omega], 0]/Q x'[t]+(Subscript[\[Omega], 0]^2)[1+Subscript[c, 0]Subscript[V, 1][t]]x[t]==\[CapitalGamma] Sin[Subscript[\[Omega], 0]t+\[Phi]]//Simplify;
sol=NDSolve[{eqn,x[0]==1/2,x'[0]==0},x[t],{t,0,25}][[1]]
ParametricPlot[Evaluate[{x[t]/.sol,D[x[t]/.sol,t]}],{t,0,25},Frame->True,AxesLabel->{"t",Overscript[\[Theta],"."]},AspectRatio->1]

Errors:

Set::write: Tag Times in (0.707107 Sin[20 t])[t] is Protected. >>

NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.`. >>



Plz suggest what shall i do to get the solution.


Regards,
rc

Bob Hanlon

unread,
Jul 6, 2012, 3:25:18 AM7/6/12
to
Until you spend the time to learn basics you will continue to make the
same mistakes. You also need to pay attention to details.

You used Subscript[C, 0] and Subscript[c, 0]; pick one.

You cannot use square brackets as if they were parentheses.

Subscript[\[Gamma]\[Omega], 0] should be \[Gamma] Subscript[\[Omega], 0]


Clear[x, Q, \[CapitalGamma], \[Phi]];
Q = 100;
\[CapitalGamma] = 50;
Subscript[\[Omega], 0] = 10;
Subscript[V, p] = 1/2;
Subscript[c, 0] = 406*10^-6;
\[Phi] = 90;
\[Gamma] = 1/Q;
Subscript[V, 1][t] =
Sqrt[2] Subscript[V, p] Sin[2 Subscript[\[Omega], 0] t];

eqn = x''[t] + \[Gamma] Subscript[\[Omega], 0] x'[
t] + (Subscript[\[Omega], 0]^2) (1 +
Subscript[c, 0] Subscript[V, 1][t]) x[
t] - \[CapitalGamma] Sin[Subscript[\[Omega], 0] t + \[Phi]] ==
0 // Simplify;

sol = NDSolve[{eqn, x[0] == 1/2, x'[0] == 0}, x[t], {t, 0, 25}][[1]];

Manipulate[
ParametricPlot[
Evaluate[{x[t] /. sol, D[x[t] /. sol, t]}], {t, 0, ub},
Frame -> True, AxesLabel -> {"t", Overscript[\[Theta], "."]},
AspectRatio -> 1,
PlotRange -> {{-40, 40}, {-400, 400}}],
{ub, Range[5, 25, 5]}]


Bob Hanlon


On Thu, Jul 5, 2012 at 6:11 AM, Rahul Chakraborty <rahul...@gmail.com> wrote:
> Following is the code as modified:
>
> Clear[x,Q,\[CapitalGamma],\[Phi]];
> Q=100;
> \[CapitalGamma]=50;
> Subscript[\[Omega], 0]=10;
> Subscript[V, p]=1/2;
> Subscript[C, 0]=406 * 10^-6;
> \[Phi]=90;
> \[Gamma]=1/Q;
> Subscript[V, 1][t]=Sqrt[2] Subscript[V, p]Sin[2Subscript[\[Omega], 0]t];
> eqn= x''[t]+Subscript[\[Gamma]\[Omega], 0]x'[t]+(Subscript[\[Omega], 0]^2)[1+Subscript[c, 0]Subscript[V, 1][t]]x[t]-\[CapitalGamma] Sin[Subscript[\[Omega], 0]t+\[Phi]]==0//Simplify;
> sol=NDSolve[{eqn,x[0]==1/2,x'[0]==0},x[t],{t,0,25}][[1]]
> ParametricPlot[Evaluate[{x[t]/.sol,D[x[t]/.sol,t]}],{t,0,25},Frame->True,AxesLabel->{"t",Overscript[\[Theta],"."]},AspectRatio->1]
>
>
> ERROR showing as follows:
>
> NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.`. >>
>
> Plz advice me how to correct this error.
>
> Regards,
>
> rc
>



--
Bob Hanlon

0 new messages