MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: NDSolve problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101709] Re: [mg101688] Re: [mg101657] NDSolve problem
  • From: Haibo Min <yshdfeng at gmail.com>
  • Date: Wed, 15 Jul 2009 07:07:35 -0400 (EDT)
  • References: <200907121058.GAA19030@smc.vnet.net>

Thank you for your reply, Elton Kurt TeKolste.

I think your suggestion is right, e1 has to be defined before the NDSovle
process. Actually e1 is a vector, i.e., e1[t] := Table[Subscript[e1, i][t],
{i, 4}], or explicitly,
e1[t_] := {e11[t], e12[t], e13[t], e14[t]}
But to NDSolve, this definition may not work. We know that in NDSolve, the
equations are denoted by ==, not =. Therefore, if we define variables in
advance, mathematica will tell us that "NDSolve::ndode : Input is not an
ordinary differential equation."  I still have no idea how to solve this
problem.
The following example from the mathematica help document is a typical one in
which the arguments of NDSolve are vector-valued functions, so I think
mathematica is capable to solve my problem.

s = NDSolve[{
\!\(\*SuperscriptBox["y", "\[Prime]\[Prime]",
MultilineFunction->None]\)[x] + \!\(\*
TagBox[
RowBox[{"(", "\:f3a2", GridBox[{
{"1", "1", "1", "1"},
{"1", "2", "1", "2"},
{"1", "1", "3", "1"},
{"1", "2", "1", "4"}
},
GridBoxAlignment->{
            "Columns" -> {{Left}}, "ColumnsIndexed" -> {},
             "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{
            "Columns" -> {0.28, {0.7}, 0.28}, "ColumnsIndexed" -> {},
             "Rows" -> {0.2, {0.4}, 0.2}, "RowsIndexed" -> {}}],
          "\:f3a2", ")"}],
Function[BoxForm`e$,
MatrixForm[BoxForm`e$]]]\).y[x] == 0, y[0] ==
\!\(\*SuperscriptBox["y", "\[Prime]",
MultilineFunction->None]\)[0] == {1, 1, 1, 1}}, y, {x, 0, 8}];
Plot[y[x] /. First[s], {x, 0, 8}]

Thanks all the same~
Best regards,
Haibo


On Tue, Jul 14, 2009 at 5:37 PM, Elton Kurt TeKolste
<tekolste at fastmail.us>wrote:

> Haibo
>
> I have placed the Mathematica notebook corresponding to this reply at
>
>    http://sites.google.com/site/mathematicaworkingpapers/
> under the name NDSolve
>
> **************************************************
> You are trying to access the elements of a list when you have no list.
> For example, e1[t] is undefined:
>
> e1[t]
> e1[t]
> so it is possible to do only symbolic manipulations on e1[t].  Since
> e1[t] is an undefined function, its zeroth part is the head (function
> name) and its first part is the dummy variable (t):
> {Part[e1[t],0],Part[e1[t],1]}
> {e1,t}
> Or, equivalently
> {e1[t][[0]],e1[t][[1]]}
> {e1,t}
> But e1[t] has no second part
> e1[t][[2]]
> Part::partw: Part 2 of e1[t] does not exist. >>
> e1[t][[2]]
> So you get an error message from the attempt to access e1[t] in the
> execution of the function EE.
>
> You must explicity, if symbolically, define the components of e1[t].
> for example
> e1[t]:=Table[Subscript[e1, i][t],{i,4}]
> Then
> EE[e1[t]]//MatrixForm
> (Subscript[e1, 2][t]/2  Subscript[e1, 3][t]/2   Subscript[e1, 4][t]/2
> 1/2 (1-Subscript[e1, 1][t])     -(1/2) Subscript[e1, 4][t]
> Subscript[e1, 3][t]/2
> Subscript[e1, 4][t]/2   1/2 (1-Subscript[e1, 1][t])     -(1/2)
> Subscript[e1, 2][t]
> -(1/2) Subscript[e1, 3][t]      Subscript[e1, 2][t]/2   1/2
> (1-Subscript[e1, 1][t])
>
> )
> Unfortunately, fixing this only reveals another problem:
> NDSolve[{J.e2'[t]==-kq Transpose[EE[e1[t]]].e1[t]-komega
> (IdentityMatrix[3]+4
>
> Transpose[G[e1[t]]]).\[CurlyTheta][t]-(J.S[e2[t]+\[Omega][t]].(e2[t]+\[Omega][t])+S[e2[t]+\[Omega][t]].J.(e2[t]+\[Omega][t])),\[CurlyTheta]'[t]==-a
> \[CurlyTheta][t]+b (1/4
>
> IdentityMatrix[3]+G[e1[t]]).e2[t],e1'[t]==EE[e1[t]].e2[t],e1[0]=={1+0.3772,-0.4329,0.6645,0.4783},\[CurlyTheta][0]=={0.3,0.4,0.2},e2[0]=={0.1,0.2,0.3}},{e1,\[CurlyTheta],e2},{t,0,500}]
>
> NDSolve::dvnoarg: The function e1 appears with no arguments. >>
> It seems that you are integrating over e1, which does not feel
> consistent with definition of e1[t] as a 4-vector.
>
> At this point I find your symbolism too obscure to be able to puzzle out
> your intention.  Do you mean functions (e1[t_],  e2[t_],...), vectors
> (e1 = {e1[[1]],e1[[2]],...}), a vcctor-valued function (e1[t] =
> {Subscript[e1, 1][t], Subscript[e1, 2][t], ...}), or something else?
> I cannot find an example in which the arguments of NDSolve are
> vector-valued functions.  In fact, a short experiment reveals that you
> cannot define boundary conditions as vectors:
> e1[t]
> {Subscript[e1, 1][t],Subscript[e1, 2][t],Subscript[e1,
> 3][t],Subscript[e1, 4][t]}
> e1[0]=Range[4]
> {1,2,3,4}
> Subscript[e1, 1][0]
> Subscript[e1, 1][0]
> e1[0]
> {1,2,3,4}
> I conclude that it will be necessary to specifiy the boundary conditions
> on the components of e1 separately.
>
> On Sun, 12 Jul 2009 02:58 -0400, "Haibo Min" <haibo.min at gmail.com>
> wrote:
>  > Hi, there.
> > These days, I am using mathematica to conduct a simulation which is
> > composed
> > of a set of matrix ODEs. Maybe there is something wrong in my function
> > definition or the usage of NDSolve, when implementing the NDSolve
> > function,
> > it always tells me that some part of my variables do not exist! I am
> > really
> > puzzled by this. Since the simulation program is pretty short. I paste
> > the
> > code here, thanks for your time and hints in advance.
> >
> >
> > S[Px_] := ( {
> >     {0, -Px[[3]], Px[[2]]},
> >     {Px[[3]], 0, -Px[[1]]},
> >     {-Px[[2]], Px[[1]], 0}
> >    } );
> > EE[err_] := 1/2 ( {
> >      {err[[2]], err[[3]], err[[4]]},
> >      {1 - err[[1]], -err[[4]], err[[3]]},
> >      {err[[4]], 1 - err[[1]], -err[[2]]},
> >      {-err[[3]], err[[2]], 1 - err[[1]]}
> >     } );
> > G[e_] := 1/2 ( {
> >       {1 - e[[1]], -e[[4]], e[[3]]},
> >       {e[[4]], 1 - e[[1]], -e[[2]]},
> >       {-e[[3]], e[[2]], 1 - e[[1]]}
> >      } ) - 1/4 IdentityMatrix[3];
> > J = ( {
> >     {4.35, 0, 0},
> >     {0, 4.337, 0},
> >     {0, 0, 3.664}
> >    } );
> > T = 5000; c = \[Pi]/T;
> > \[Omega][t_] := 1/5 {-5 cSin[2 ct], 8 cSin[4 ct], 4 cSin[2 ct]};
> > kq = 1.2; komega = 4; a = 5; b = 20;
> >
> > NDSolve[{J.e2'[t] == -kq Transpose[EE[e1[t]]].e1[t] -
> >     komega (IdentityMatrix[3] + 4 Transpose[G[e1[t]]]).\[CurlyTheta][
> >        t] - (J.S[e2[t] + \[Omega][t]].(e2[t] + \[Omega][t]) +
> >       S[e2[t] + \[Omega][t]].J.(e2[t] + \[Omega][t])), \[CurlyTheta]'[
> >     t] == -a \[CurlyTheta][t] +
> >     b (1/4 IdentityMatrix[3] + G[e1[t]]).e2[t],
> >   e1'[t] == EE[e1[t]].e2[t],
> >   e1[0] == {1 + 0.3772, -0.4329, 0.6645, 0.4783}, \[CurlyTheta][
> >     0] == {0.3, 0.4, 0.2},
> >   e2[0] == {0.1, 0.2, 0.3}}, {e1, \[CurlyTheta], e2}, {t, 0, 500}]
> >
> >
> > When evaluating the above code, error occurs:
> > Part::partw: Part 2 of e1[t] does not exist. >>
> > Part::partw: Part 3 of e1[t] does not exist. >>
> > Part::partw: Part 4 of e1[t] does not exist. >>
> >
> > It seems that mathematica does not know what e1 is since e1 is also a
> > parameter of EE and G, which are included in the ODE equation. Does that
> > mean that I have to give a definition of e1? But if so, it still doesn't
> > make sense in the NDSolve function...
> >
> >
> > Any suggestion will be appreciated.
> >
> > Best regards,
> >
> > Haibo
> >
> >
>
>


  • Prev by Date: Re: Interactive .nb works, but converted .nbp fails
  • Next by Date: Modify variable names in a loop
  • Previous by thread: Re: NDSolve problem
  • Next by thread: Re: NDSolve problem