Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #8837 > unrolled thread
| Started by | jie zhao <nbt3710@gmail.com> |
|---|---|
| First post | 2012-03-02 12:55 +0000 |
| Last post | 2012-03-03 11:54 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
how to sovle array which odd and even have difference recursive function jie zhao <nbt3710@gmail.com> - 2012-03-02 12:55 +0000
Re: how to sovle array which odd and even have difference recursive function danl@wolfram.com - 2012-03-03 11:54 +0000
| From | jie zhao <nbt3710@gmail.com> |
|---|---|
| Date | 2012-03-02 12:55 +0000 |
| Subject | how to sovle array which odd and even have difference recursive function |
| Message-ID | <jiqfv7$8d$1@smc.vnet.net> |
RSolve[{(b[n] == 1 + b[n/2] && Mod[n, 2] == 0) && (b[n] == 1/n &&
Mod[n, 2] == 1)}, b[n]==2, n] failed to work !
when n is odd b[n] == 1/n
when n is even b[n] == 1 + b[n/2]
[toc] | [next] | [standalone]
| From | danl@wolfram.com |
|---|---|
| Date | 2012-03-03 11:54 +0000 |
| Message-ID | <jit0pb$e4h$1@smc.vnet.net> |
| In reply to | #8837 |
On Friday, March 2, 2012 6:55:03 AM UTC-6, jie zhao wrote:
> RSolve[{(b[n] == 1 + b[n/2] && Mod[n, 2] == 0) && (b[n] == 1/=
n &&
> Mod[n, 2] == 1)}, b[n]==2, n] failed to work !
> when n is odd b[n] == 1/n
> when n is even b[n] == 1 + b[n/2]
Could do as follows. Solve a symbolic recurrence with base an arbitrary odd, and successive elements equal to powers of 2 times that base. So it will be a recurrence in two variables (more accurately, in one variable, parametrized by another). Then put this to use on an arbitrary input by breaking it into 2^power*odd.
In[30]:= bsol[o_, p_] =
First[RSolve[{b[odd, 0] == 1/odd,
b[odd, pwr] == 1 + b[odd, pwr - 1]},
b[odd, pwr], {odd, pwr}]] /. {odd -> o, pwr -> p};
f[n_] := Module[{pwr = IntegerExponent[n, 2], odd},
odd = n/2^pwr;
b[odd, pwr] /. bsol[odd, pwr]
]
In[32]:= SetAttributes[f, Listable]
In[33]:= f[Range[20]]
Out[33]= {1, 2, 1/3, 3, 1/5, 4/3, 1/7, 4, 1/9, 6/5, 1/11, 7/3, 1/13,
8/7, 1/15, 5,
1/17, 10/9, 1/19, 11/5}
Daniel Lichtblau
Wolfram Research
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web