MathGroup Archive 2008

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

Search the Archive

Re: For Loop and NDSolve

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

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
issue)::
Assume all constants as before in the last post,
then::

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

timevol[f_,j_,wave_]:=
  Module[{solnmatrix,C1},
    t = j*delt;
    solnmatrix = -I/c3*SparseArray[{{i_,i_} -> (-V0[f]/2 + ((i-
(4*N0+1))*
    k0-2*t)^2),{m_,n_}/;Abs[m-
      n] == N0 -> -V0[f]/4},{24*N0+1,24*N0+1}] ;
    soln =
              NDSolve[{u'[p] == solnmatrix.u[p],u[0] == wave},u,{p,
                        0,delt}];
    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@(
                Conjugate[Take[wave,{N0+1,24*
    N0+1}]]*Take[wave,{1,23*N0+1}]))*L;
    insfn[C1,f]>>>flist;
    ]
a>>flist

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!

Cheers

Prasanna

On Feb 2, 11:39 pm, PV <prasanna.p... at gmail.com> 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 gmail.com> 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