       Re: For Loop and NDSolve

• To: mathgroup at smc.vnet.net
• Subject: [mg85227] Re: For Loop and NDSolve
• From: PV <prasanna.phys at gmail.com>
• Date: Sat, 2 Feb 2008 23:31:21 -0500 (EST)
• References: <fnuh4s\$9ni\$1@smc.vnet.net> <fo19o9\$fu8\$1@smc.vnet.net>

```Hello Here is a stand alone version of my code, I have not got rid of
the for loop as suggested by Szabolcs here but Iam trying something
like that right now! I would be grateful to anybody who can give me a
hint or two abot which part of this code is eating up excessive
memory!
Cheers
Prasanna
(**********************************)
c3 = 0.035896
N0 = 80
k0  = 1/40
L  = 80 =A6=D0
=A6=C7 = 1.0485203*10^6
=A6=C3  = 1.85353*^6
=A6=CA = 3.707*^6
delt  =  1/1000

a = 0.26452763498582404

V0[a_]:= 79.06*Abs[a]^2

deltanew[n_]:= If [Mod[n,N0]==0, N0*1/(Sqrt[L])*NIntegrate[E^(-I*n*k0*=

z)*MathieuC[-0.81399423,-1.383053249,z],{z,0,Pi}], 0]
list1 = 1/(L)*Chop[Table[deltanew[n],{n,-4*N0,4*N0}]];

fieldlist3 = {}
couplinglist = {}
normlist = {}
For[j=1,j=A1=DC100,
t = j*1/1000;
solnmatrix =-I/c3* 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}] ;
soln = NDSolve[{u'[p]== solnmatrix.u[p],u==wavefn},u,{p,0,del=
t}];

wavefn = First[u[delt]/.soln];
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= -=A6=C7/(I*=A6=C3*C1 - =A6=CA) + ((=A6=C7 + (I*=A6=C3*C1 - =A6=CA)*
a )/(I*=A6=C3*C1 - =A6=CA))*E^(delt*0.0011*(I*=A6=C3*C1 - =A6=CA));

a = b;
AppendTo[fieldlist3,a];
AppendTo[normlist,L*Tr[Abs[wavefn]^2]];
AppendTo[couplinglist,C1];
j++;
]

(******************************)

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}}, 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: Re: changing color of non-evaluatable cell
• Previous by thread: Re: For Loop and NDSolve
• Next by thread: Re: For Loop and NDSolve