Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #10117
| From | Peter Breitfeld <phbrf@t-online.de> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Trying to recursively define a double factorial |
| Date | 2012-05-17 08:11 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jp2brl$4v1$1@smc.vnet.net> (permalink) |
| References | <jovo6m$mhq$1@smc.vnet.net> |
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
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
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
csiph-web