MathGroup Archive 2007

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

Search the Archive

Re: Better recursive method?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72827] Re: Better recursive method?
  • From: Jon Harrop <jon at ffconsultancy.com>
  • Date: Sun, 21 Jan 2007 05:57:48 -0500 (EST)
  • References: <eosh0f$9bs$1@smc.vnet.net>

nandan wrote:
> This should be pretty easy to calculate for Mathematica. I have written
> it the following way:
> pi[0,theta] := 0;
> pi[1,theta] := 1;

These should probably be theta_ instead of theta.

> pi[i_, theta_] := pi[i, theta] =(2n-1)/(n-1) Cos[theta] pi[i-1, theta]
> - n/(n-1) pi[i-2,theta]
> tau[i_,theta_] := n pi[i, theta] - (n+1) pi[i-1,theta]
> S1Temp[i_,theta_] := (2i+1)/(i(i+1)) (a[i] pi[i,theta] - b[i]
> tau[i,theta])
> S1(theta) := Sum[ S1Temp[i,theta], {i, 1, nstop}]
> 
> Well, it works fine, but it takes enormous time.

Can you give an example of a computation that takes a long time?

Do you want a symbolic answer in terms of n and/or theta?

> I have introduced 
> recursive function to save time for calculation of Legendre Polynomials
> of which the function 'pi' and 'tau' consist of. But the same function
> if I write with 2 loops each for 'theta' and 'i' in IDL, it calculates
> in fraction of a second. Even the simple calculation of 'pi[40,pi/4]'
> took more than 350 seconds.

With the above fix that takes 0.000077s here.

-- 
Dr Jon D Harrop, Flying Frog Consultancy
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet


  • Prev by Date: Re: how to quickly read a >10MB big file
  • Next by Date: simple equation manipulation
  • Previous by thread: Re: Better recursive method?
  • Next by thread: Re: Better recursive method?