Re: Better recursive method?

• To: mathgroup at smc.vnet.net
• Subject: [mg72831] Re: Better recursive method?
• From: Johan Grönqvist <johan.gronqvist at gmail.com>
• Date: Sun, 21 Jan 2007 06:14:02 -0500 (EST)
• References: <eosh0f\$9bs\$1@smc.vnet.net>

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

I believe this should be pi[0,theta_] := 0

> pi[i_, theta_] := pi[i, theta] =(2n-1)/(n-1) Cos[theta] pi[i-1, theta]
> - n/(n-1) pi[i-2,theta]

Here n is a free variable, and I get a huge expression when trying to
evaluate this. Is it correct to guess that n should be i?

I also believe that in general it is best to add an N[...] in the
definition of pi, to avoid a large polynomial expression in rational
numbers and Cos[theta].

If that is the case, and after setting \$RecursionLimit = Infinity, it
takes me 0.052003 Second to calculate pi[1000,1].

My kernel quits silently when attempting pi[10000,1], and I would be
interested in knowing why.

> in IDL, it calculates
> in fraction of a second. Even the simple calculation of 'pi[40,pi/4]'
> took more than 350 seconds.
>
> What could be the problem in my logic. Is there any other better way to
> write recursive functions in Mathematica?
>
I believe it is about avoiding analytical expressions when you only want