MathGroup Archive 2007

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

Search the Archive

Re: Solving differential equations with parameters

  • To: mathgroup at smc.vnet.net
  • Subject: [mg79836] Re: Solving differential equations with parameters
  • From: "Jean-Marc Gulliet" <jeanmarc.gulliet at gmail.com>
  • Date: Mon, 6 Aug 2007 03:38:40 -0400 (EDT)
  • References: <f91j5e$677$1@smc.vnet.net> <f9445k$mdg$1@smc.vnet.net>

On 8/5/07, Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com> wrote:
> Ivan wrote:
> > On Aug 4, 12:07 pm, Ivan <darkna... at gmail.com> wrote:
> >> Hi, I am trying to solve the differential equations like
> >>
> >> y'[x]= - Sin[ p*x + y[x] ]
> >>
> >> where p is a parameter. Now I want to solve the equation with respect
> >> to x for a range of values of p, instead for just a single p.
> >> What is the best way to do it?
> >
> > I now have a way to do it but there is another problem..
> >
> > I use the Table command (I change the function for the sake of
> > demonstration)
> >
> > sol = NDSolve[{y'[x]==1/2y[x],y[0.01]==0.1}, y, {x, 0.01,1}];
> >
> > g=Table[ {y[i*0.01]/.sol}, {i,100} ];
> >
> > ListPlot[g];
> >
> > The error message is gptn: Coordindate .. in ... is not a floating-
> > point number.
> >
> > The problem seems to be that y[x]/.sol generate not a "normal" number,
> > instead, the number is is a brace {...}.
> >
> > Can anyone help me?
>
> Use y[x]/.sol[[1]] or y[x]/.First[sol]

Sorry, I was too quick to answer and had not tested the code before
replying. (It won't work on 5.2 and yields an erroneous plot in 6.0.)

The correct answer is that you must use *Flatten* to get a list of
numbers suitable to ListPlot*. For instance,

sol = NDSolve[{y'[x] == 1/2y[x], y[0.01] == 0.1}, y, {x, 0.01, 1}];
g = Flatten[Table[{y[i*0.01] /. sol[[1]]}, {i, 100}]];
ListPlot[g];

Regards,
Jean-Marc


  • Prev by Date: Re: Re: Solving differential equations with parameters
  • Next by Date: Re: Re: Changing "point" styles in 3D plots
  • Previous by thread: Re: Re: Solving differential equations with parameters
  • Next by thread: Re: Solving differential equations with parameters