Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

Re: Question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22645] Re: [mg22576] Question
  • From: Hartmut Wolf <hwolf at debis.com>
  • Date: Thu, 16 Mar 2000 09:11:03 -0500 (EST)
  • Organization: debis Systemhaus
  • References: <200003112252.RAA03305@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

aranisin schrieb:
> 
> In the following code, the program takes more
> runtime and memory resources than that allowed
> by my system.  The suspected code is underlined.
> Is there a better way of writing this code?
> 
--.--.--
> 
> R11=2;
> R22=2;
> 
> L11=10^-9;
> L22=10^-9;
> L12=5 10^-10;
> 
> C11=25 10^-15;
> C22=25 10^-15;
> C12=15 10^-15;
> 
> Rs1=50;
> Rs2=50;
> 
> Cs1=10^-14;
> Cs2=10^-14;
> 
> a=4.24 10^10;
> 
> D1={{0,0,-R11,0},
>     {0,0,0,-R22},
>     {0,0,0,0},
>     {0,0,0,0}};
> 
> E1={{0,0,-L11,-L12},
>     {0,0,-L12,-L22},
>     {-C11,C12,0,0},
>     {C12,-C22,0,0}};
> 
> X=D1+s E1;
> Y=MatrixExp[X];
> 
> A={{1/Rs1,0,0,0,1,0,0,0},
>    {0,1/Rs2,0,0,0,1,0,0},
>    {0,0,s Cs1,0,0,0,-1,0},
>    {0,0,0,s Cs2,0,0,0,-1},
>    {Y[[1,1]],Y[[1,2]],-1,0,Y[[1,3]],Y[[1,4]],0,0},
>    {Y[[2,1]],Y[[2,2]],0,-1,Y[[2,3]],Y[[2,4]],0,0},
>    {Y[[3,1]],Y[[3,2]],0,0,Y[[3,3]],Y[[3,4]],-1,0},
>    {Y[[4,1]],Y[[4,2]],0,0,Y[[4,3]],Y[[4,4]],0,-1}};
> 
> Vs=1/(s+a);
> V={{Vs/Rs1},{0},{0},{0},{0},{0},{0},{0}};
> 
> M[i_]:=M[i]=D[M[i-1],s];
> M[0]=A;
> Z[i_]:=Z[i]=(Limit[M[i],s->0,Direction->1])/(Factorial[i]);
> 
> P[k_]:=P[k]=-Inverse[Z[0]].(Sum[Z[r].P[(k-r)],{r,1,k}]);
> --------------------------------------------------------
> P[0]=Inverse[Z[0]].V;
> ---------------------
> Q=P[0]+s P[1]+s^2 P[2]+s^3 P[3]+s^4 P[4]+s^5 P[5];
> -------------------------------------------------



Arani Sinha,

on Monday I started your program (to execute in steps for P[i] {i,0,5}),
left my office, took the tram downtown, went to the university book
store, bought a nice book "Modern Computer Algebra", had lunch, went
back into my office and the Flying Window Flag was still frozen; so I
began reading. After a while, to my great astonishment, when my eyes
left the pages for a moment, I saw the flag waving:

times = Out[#][[1, 1]] & /@ Delete[Range[31, 43, 2], 2]
{9.914, 58.534, 239.605, 810.705, 2194.36, 5454.03}

memory = Out[#] & /@ Delete[Range[32, 44, 2], 2]
{2091104, 2489560, 3357824, 5362344, 9668008, 18079024}

<< Graphics`MultipleListPlot`

MultipleListPlot[times, memory/4000, PlotJoined -> True, 
  PlotStyle -> {Hue[0.08, 1., 1.], Hue[0.65, 1., 0.7]}]

times is the Timing for the P[<i>], memory is MaxMemoryUsed[] after the
respective steps.

What is conspicious with your calculation is: (1) you are doing exact
numerics although the precision of the constants of your theory may be
low (are 5, 25, 50 exact integers?), but perhaps that is essential for
taking the limits for the Z[<i>]. (2) the model you start with is of
considerate complexity (8 x 8 matrices). (3) Your Q seems to be an
(approximate) expansion (to order 5), why not start with order 1 and
test everything first (including the theory)?

What costs your computational resources is taking the limits for the
Z[i]. That's where you have to work at (if you cannot reduce for a while
the complexity of the problem (1) - (3) above).

For i=0 and i=1 there is no difference if you take the limit from below
(as you did), or from above.

Although you save the values for M[i], Z[i], P[i] you possibly do much
work over an over, see:

 
In[44]:= Map[(# /. {Plus -> List, Times -> term} &), M[0], {2}];
In[45]:= Length[Flatten[%, 1]]
Out[45]= 64

In[46]:= Flatten[%%];
In[47]:= Length[%]
Out[47]= 112

In[48]:= Union[%%];
In[49]:= Length[%]
Out[49]= 23

So for M[0] you generated 112 terms, but only 23 are different.

For M[1] there are 352 terms, 90 different.

So if you bet on your theory, you could work down on the individual
terms. Categorize them, simplify them, and take the limits there
seperatly (and only where really needed). From all that finally
reconstruct your expression Q (to the necessary order).

I'm sorry, but can't give better help.


Hartmut


  • References:
    • Question
      • From: aranisin@usc.edu (aranisin)
  • Prev by Date: Re: Re: Suppressing display of LogPlots
  • Next by Date: Re: Suppressing display of LogPlots
  • Previous by thread: Question
  • Next by thread: Suppressing display of LogPlots