MathGroup Archive 2004

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

Search the Archive

Re: i dont understand module.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg46563] Re: i dont understand module.
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Mon, 23 Feb 2004 22:33:45 -0500 (EST)
  • Organization: Universitaet Leipzig
  • References: <c1ampd$460$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

you multiply a NDSolve[] call with a Plot[] function call
and wonder that you get out nonsense ??

Insert a ";"

Module[{}, 
  sol = NDSolve[{a'[t] == -0.1` a[t] x[t], b'[t] == -0.05` b[t] y[t], 
          x'[t] == -0.1` a[t] x[t] + 0.05` b[t] y[t], 
          y'[t] == 0.1` a[t] x[t] - 0.05` b[t] y[t], a[0] == 1, b[0] ==
1, 
          x[0] == 1, y[0] == 0}, {a, b, x, y}, {t, 0, 250}][[1]] ; 
  Plot[Evaluate[#[[2]][t] & /@ sol], {t, 0, 250}, 
    PlotStyle -> Table[Hue[(k + 1)/6], {k, 4}], Frame -> True, Axes ->
False, 
    PlotLegend -> (#[[1]] & /@ sol), LegendPosition -> {1, -.35}, 
    LegendShadow -> {0, 0}, ImageSize -> 400];]


and all works fine.

Regards
  Jens

sean kim wrote:
> 
> hello goup.
> 
> I just don't get this. this code was posted while back by Bob Hanlon.
> 
> All i did was to flank the routine by a module. i did so to minimize
> memory used. I was hoping that by keepign things local, i can minimize
> the resources used in the routine.
> 
> In[1]:=
> Needs["Graphics`"];
> 
> Module[{},
>   sol=NDSolve[{a'[t]==-0.1` a[t] x[t], b'[t]==-0.05` b[t] y[t],
>               x'[t]==-0.1` a[t] x[t]+0.05` b[t] y[t],
>               y'[t]==0.1` a[t] x[t]-0.05` b[t] y[t],
> a[0]==1,b[0]==1,x[0]==1,
>               y[0]==0}, {a,b,x,y},{t,0,250}][[1]]
> 
>         Plot[Evaluate[#[[2]][t]& /@ sol],{t,0,250},
>           PlotStyle->Table[Hue[(k+1)/6],{k,4}], Frame->True,
> Axes->False,
>           PlotLegend->(#[[1]]& /@ sol), LegendPosition->{1,-.35},
>           LegendShadow->{0, 0} , ImageSize->400];
>   ]
> above fails with the following error.
> 
> Plot::plnr: sol is not a machine-size real number at t = \
> 0.000010416666666666666`.
> 
> if i flank the module with Do loop, then I get recursion errors
> 
> In[5]:=
> Needs["Graphics`"];
> 
> Do[
>   Module[{},
>     sol=NDSolve[{a'[t]==-0.1` a[t] x[t], b'[t]==-0.05` b[t] y[t],
>                 x'[t]==-0.1` a[t] x[t]+0.05` b[t] y[t],
>                 y'[t]==0.1` a[t] x[t]-0.05` b[t] y[t],
> a[0]==1,b[0]==1,
>                 x[0]==1,y[0]==0}, {a,b,x,y},{t,0,250}][[1]]
> 
> 
>           Plot[Evaluate[#[[2]][t]& /@ sol],{t,0,250},
>             PlotStyle->Table[Hue[(k+1)/6],{k,4}], Frame->True,
> Axes->False,
>             PlotLegend->(#[[1]]& /@ sol), LegendPosition->{1,-.35},
>             LegendShadow->{0, 0} , ImageSize->400];
>     ],
>   {iteration, 10}]
> 
> $RecursionLimit::reclim: Recursion depth of 256 exceeded.
> 
> what's going on here?  and how do i fix it so that i can run it
> automatically?
> 
> thanks all in advance.
> 
> sean


  • Prev by Date: Re: Can Mathematica Ver 5 Import ESRI *.shp, *.shx and DBase *.dbf files??
  • Next by Date: Re: Annotating Mathematica EPS files with Illustrator
  • Previous by thread: Re: i dont understand module.
  • Next by thread: need favor