MathGroup Archive 2008

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

Search the Archive

Re: For Loop and NDSolve

  • To: mathgroup at
  • Subject: [mg85242] Re: For Loop and NDSolve
  • From: PV <prasanna.phys at>
  • Date: Mon, 4 Feb 2008 03:08:44 -0500 (EST)
  • References: <fnuh4s$9ni$> <fo19o9$fu8$>

Hello All,
I have finally figured out which part of my code is the culprit. It is
the fact that I need to use the value of wavefn calculated at time t
in the loop calculation for time t+delt, this means that inside the
For loop I have the statement
wavefn = First[u[delt]/.soln];
This consumes a huge amount of memory and I have tried many ways to
get away from this statement but nothing works, the last and my best
attempt was to do this(this implements most of Szabolcs' advise on the
Assume all constants as before in the last post,

insfn[n_,f_]:= -=E7/(
    I*=E3*n - =EA) + ((=E7 + (I*=E3*n - =EA)*f )/(I*=E3*n - =EA))*E^(delt*Tb=
- =EA))

    t = j*delt;
    solnmatrix = -I/c3*SparseArray[{{i_,i_} -> (-V0[f]/2 + ((i-
      n] == N0 -> -V0[f]/4},{24*N0+1,24*N0+1}] ;
    soln =
              NDSolve[{u'[p] == solnmatrix.u[p],u[0] == wave},u,{p,
    C1 = ( Tr[Abs[wave]^2/2]+0.25*Total@(Conjugate[Take[wave,{1,23*
              N0+1}]]*Take[wave,{N0+1,24*N0+1}]) + 0.25*Total@(

extsol[t_]:= If[t\[Equal]0,wavefn,First[u[delt]/.soln]]

Table[timevol[<<flist, j, extsol[t]],{j,1,100}]

Even after this, the last statement consumes huge amount of memory!

I am not sure what else to do!



On Feb 2, 11:39 pm, PV <prasanna.p... at> wrote:
> Hello Szabolocs,
> I have already tried a few of the things you have mentioned though I
> did not talk about that. I used a Do loop instead of a For loop and as
> you suspected it did not change things very much. I shall carry out
> few other suggestions that you have talked about and get back to you.
> The Sparse array is actually a general tridiagonal as in it has the
> main diagonal non zero plus two other diagonals "N0"units away from
> the diagonal non-zero.
> My only issue with this arises out of the fact that I had the same
> sized matrix before for different parameters and it worked normally!
> Anyways, I am grateful to you for taking some time to look at the
> stuff I posted!
> Cheers
> PV
> On Feb 2, 3:31 am, Szabolcs <szhor... at> wrote:
> > One more thing .... since that sparse array is diagonal you might try
> > using a vector instead, something like
> > f[x_?VectorQ] := {1, 2} x
> > NDSolve[{u'[t] == f[u[t]], u[0] == {0, 0}}, u, {t, 0, 1}]
> > This make make things better ... or worse ...

  • Prev by Date: Re: Possible bug in ListAnimate[] or Manipulate[] v6.0
  • 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