Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: For Loop and NDSolve

  • To: mathgroup at smc.vnet.net
  • Subject: [mg85254] Re: For Loop and NDSolve
  • From: "Jean-Marc Gulliet" <jeanmarc.gulliet at gmail.com>
  • Date: Mon, 4 Feb 2008 03:14:55 -0500 (EST)
  • References: <fnuh4s$9ni$1@smc.vnet.net> <47A4A595.4000601@gmail.com>

PV wrote:

> I am trying to solve a time dependent ordinary differential equation
> of matrices. Here my coefficient matrices in the DE change at every
> instant of time, depending on the solution of the DE in the previous
> instant( feed back type problem). To implement this I use NDSolve with
> a For loop in time. This works fine for certain size of my matrices
> but has got me into trouble for other sizes. I run out of memory
> pretty quickly. I have 1 GB  Ram with an AMD X2 duo core 1.7GHZ
> processor.
> Here are the routines that cause problems::
>
> N0  = 1921(large number)

<snip>

Here, I believe you mean something like N0 = 1921(* large number *)
rather than N0 = 1921 \times (large \times number).

Even though, the peace of code is not working independently.

In[1]:= N0 = 1921(* large number *)

For[j = 1, j <= 100, t = j*delt;
  solnmatrix =
   SparseArray[{{i_,
       i_} -> (-V0[a]/2 + ((i - (4*N0 + 1))*k0 - 2*t)^2), {m_, n_} /;
       Abs[m - n] == N0 -> -V0[a]/4}, {24*N0 + 1, 24*N0 + 1}];
  Print["pbegin ", MemoryInUse[]];
  soln = NDSolve[{I*c3*u'[p] == solnmatrix.u[p], u[0] == wavefn},
    u, {p, 0, delt}];
  Print["p1 ", MemoryInUse[]];
  wavefn = First[u[delt] /. soln];
  Clear[solnmatrix];
  Clear[soln];
  Print["p2 ", MemoryInUse[]];
  C1 = (Tr[Abs[wavefn]^2/2] +
      0.25*Sum[
        Conjugate[wavefn[[n]]]*wavefn[[n + N0]], {n, 1, 23*N0 + 1}] +
      0.25*Sum[
        Conjugate[wavefn[[n]]]*wavefn[[n - N0]], {n, N0 + 1,
         24*N0 + 1}])*L;
  b = -\[Eta]/(I*\[Gamma]*
        C1 - \[Kappa]) + ((\[Eta] + (I*\[Gamma]*C1 - \[Kappa])*
          a)/(I*\[Gamma]*C1 - \[Kappa]))*
     E^(delt*Tb*(I*\[Gamma]*C1 - \[Kappa]));
  a = b;
  AppendTo[fieldlist3, a];
  AppendTo[normlist, L*Tr[Abs[wavefn]^2]];
  AppendTo[couplinglist, C1];
  j++;
  Print["pend ", MemoryInUse[]];]

Out[1]= 1921

During evaluation of In[1]:= pbegin 20397464

During evaluation of In[1]:= NDSolve::ndnl: Endpoint delt in \
{p,0.,delt} is not a real number. >>

During evaluation of In[1]:= p1 20570064

During evaluation of In[1]:= ReplaceAll::reps: {<<1>>} is neither a \
list of replacement rules nor a valid dispatch table, and so cannot \
be used for replacing. >>

During evaluation of In[1]:= p2 10720384

During evaluation of In[1]:= Part::partw: Part 1922 of u[delt] does \
not exist. >>

During evaluation of In[1]:= Part::partw: Part 2 of u[delt] does not \
exist. >>

During evaluation of In[1]:= Part::partw: Part 1923 of u[delt] does \
not exist. >>

During evaluation of In[1]:= General::stop: Further output of \
Part::partw will be suppressed during this calculation. >>

During evaluation of In[1]:= $RecursionLimit::reclim: Recursion depth \
of 256 exceeded. >>

During evaluation of In[1]:= $RecursionLimit::reclim: Recursion depth \
of 256 exceeded. >>

During evaluation of In[1]:= $RecursionLimit::reclim: Recursion depth \
of 256 exceeded. >>

During evaluation of In[1]:= General::stop: Further output of \
$RecursionLimit::reclim will be suppressed during this calculation. >>

[... Computation aborted ...]

> It would  be great if I could get a solution for this!!

The best thing to do is to post a fully working example that closely
match your problem, so people can reproduce the errors and try to fix them.

Regards,
-- 
Jean-Marc


  • Prev by Date: Re: How edit a saved palette?
  • Next by Date: RE: How edit a saved palette?
  • Previous by thread: Re: For Loop and NDSolve
  • Next by thread: Re: For Loop and NDSolve