Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #10116

Re: Trying to recursively define a double factorial

From Dana DeLouis <dana01@me.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Trying to recursively define a double factorial
Date 2012-05-17 08:10 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jp2bpn$4u3$1@smc.vnet.net> (permalink)

Show all headers | View raw


> I wanna make a recursive function of this double factorial without If(and other similar statements).

Hi.  If I understand  your question, here is one possible idea:

f[0]=f[1]=1;

f[n_Integer?Positive] := f[n] = n*f[n-2]

f[11]==11!!
True

f[12]==12!!
True

Information[ f ]

f[0]=1
f[1]=1
f[2]=2
f[3]=3
f[4]=8
f[5]=15
f[6]=48
f[7]=105
f[8]=384
f[9]=945
f[10]=3840
f[11]=10395
f[12]=46080
f[n_Integer]:=f[n]=n f[n-2]


If you meant to use RSolve, perhaps an alternative might be:

equ={
a[0]==1,
a[1]==1,
a[n]==n*a[n-2]
};

// This is a little complicated because it doesn't know if n is odd/even

z=FullSimplify[RSolve[equ,a[n],n]]   [[1,1,-1]]

(2^(1/2 (-3+n)) (2-2 (-1)^n+(1+(-1)^n) Sqrt[2 \[Pi]]) Gamma[1+n/2])/Sqrt[\[Pi]]

One technique for the Even or Odd part might be:

// Even
Assuming[Mod[n,2]==0,FullSimplify[z]]

2^(n/2) Gamma[1+n/2]

// Odd
Assuming[Mod[n,2]==1,FullSimplify[z]]

(2^((1+n)/2) Gamma[1+n/2])/Sqrt[\[Pi]]


Test of Even...

12!! == 2^(n/2) Gamma[1+n/2] /. n->12
True

= = = = = = = = = = = =
HTH   :>)
Dana DeLouis
Mac & Math 8

To understand recursion, one must first understand recursion
= = = = = = = = = = = =



On May 16, 4:23 am, Jorge Cantu <monsterb...@msn.com> wrote:
> My goal here is to define a recursive function for a double factorial.  The domain of this function is the set of positive integers.  For a positive even integer  n  the value DF[n] is the product of all positive even integers which are  <n.  For a positive odd integer   n   the value DF[n] is the product of all positive odd integers which are <n.  
> 
> I wanna make a recursive function of this double factorial without If(and other similar statements). Here is my work so far:
> 
> Clear[MyF1, n];
> MyF1[1] = 1;
> MyF1[n_Integer] /; (n > 0) := MyF1[n] = n*MyF1[n - 1]
> 
> Table[MyF1[k], {k, (*integer*), (*integer*)}]
> 
>                How do I do this?


Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Trying to recursively define a double factorial Dana DeLouis <dana01@me.com> - 2012-05-17 08:10 +0000

csiph-web