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


Groups > comp.soft-sys.math.mathematica > #10097 > unrolled thread

Trying to recursively define a double factorial

Started byJorge Cantu <monsterbone@msn.com>
First post2012-05-16 08:23 +0000
Last post2012-05-17 08:11 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Trying to recursively define a double factorial Jorge Cantu <monsterbone@msn.com> - 2012-05-16 08:23 +0000
    Re: Trying to recursively define a double factorial Peter Breitfeld <phbrf@t-online.de> - 2012-05-17 08:11 +0000

#10097 — Trying to recursively define a double factorial

FromJorge Cantu <monsterbone@msn.com>
Date2012-05-16 08:23 +0000
SubjectTrying to recursively define a double factorial
Message-ID<jovo6m$mhq$1@smc.vnet.net>
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?

[toc] | [next] | [standalone]


#10117

FromPeter Breitfeld <phbrf@t-online.de>
Date2012-05-17 08:11 +0000
Message-ID<jp2brl$4v1$1@smc.vnet.net>
In reply to#10097
Jorge Cantu 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?
>

This should work:
Clear[myF]
myF[-1] = 1
myF[0] = 1
myF[1] = 1;
myF[n_Integer?Positive] := myF[n] = n myF[n - 2]

Compare with build in !!:

Table[{myF[k], k!!}, {k, 1, 10}]

Output:
{{1, 1}, {2, 2}, {3, 3}, {8, 8}, {15, 15}, {48, 48}, {105, 105}, {384,
   384}, {945, 945}, {3840, 3840}}


-- 
_________________________________________________________________
Peter Breitfeld | Bad Saulgau, Germany | http://www.pBreitfeld.de

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web