RSolve not reducing for a certain recurrence relation
up vote
4
down vote
favorite
I'm trying to use RSolve
as follows to solve a recurrence relation:
RSolve[{a[0] == 1, a[2 n + 1] == a[2 n]*2, a[2 n] == a[2 n - 1] + 2}, a, n]
I think the meaning of the relation is clear: for odd terms in the sequence, multiply the previous term by two, and for even terms, add two to the previous term.
However, when evaluating this, Mathematica simply echos the input:
rather than attempting to solve the recurrence.
I can't find anything in the RSolve documentation which talks about cases where RSolve will do nothing, without any error message.
Have I made a syntax error, or does this mean that Mathematica is not able to solve this type of recurrence relation? How can I change my input so that Mathematica does solve the recurrence, assuming it is possible?
equation-solving symbolic syntax recursion difference-equations
New contributor
add a comment |
up vote
4
down vote
favorite
I'm trying to use RSolve
as follows to solve a recurrence relation:
RSolve[{a[0] == 1, a[2 n + 1] == a[2 n]*2, a[2 n] == a[2 n - 1] + 2}, a, n]
I think the meaning of the relation is clear: for odd terms in the sequence, multiply the previous term by two, and for even terms, add two to the previous term.
However, when evaluating this, Mathematica simply echos the input:
rather than attempting to solve the recurrence.
I can't find anything in the RSolve documentation which talks about cases where RSolve will do nothing, without any error message.
Have I made a syntax error, or does this mean that Mathematica is not able to solve this type of recurrence relation? How can I change my input so that Mathematica does solve the recurrence, assuming it is possible?
equation-solving symbolic syntax recursion difference-equations
New contributor
Try replacing the next-to-last term inRSolve
(a
) witha[n]
.
– yosimitsu kodanuri
2 days ago
It still simply echoes the input:RSolve[{a[0] == 1, a[1 + 2 n] == 2 a[2 n], a[2 n] == 2 + a[-1 + 2 n]}, a[n], n]
– konsolas
2 days ago
1
Welcome to Mathematica.SE! Interesting question(+1). I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise.
– bbgodfrey
2 days ago
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I'm trying to use RSolve
as follows to solve a recurrence relation:
RSolve[{a[0] == 1, a[2 n + 1] == a[2 n]*2, a[2 n] == a[2 n - 1] + 2}, a, n]
I think the meaning of the relation is clear: for odd terms in the sequence, multiply the previous term by two, and for even terms, add two to the previous term.
However, when evaluating this, Mathematica simply echos the input:
rather than attempting to solve the recurrence.
I can't find anything in the RSolve documentation which talks about cases where RSolve will do nothing, without any error message.
Have I made a syntax error, or does this mean that Mathematica is not able to solve this type of recurrence relation? How can I change my input so that Mathematica does solve the recurrence, assuming it is possible?
equation-solving symbolic syntax recursion difference-equations
New contributor
I'm trying to use RSolve
as follows to solve a recurrence relation:
RSolve[{a[0] == 1, a[2 n + 1] == a[2 n]*2, a[2 n] == a[2 n - 1] + 2}, a, n]
I think the meaning of the relation is clear: for odd terms in the sequence, multiply the previous term by two, and for even terms, add two to the previous term.
However, when evaluating this, Mathematica simply echos the input:
rather than attempting to solve the recurrence.
I can't find anything in the RSolve documentation which talks about cases where RSolve will do nothing, without any error message.
Have I made a syntax error, or does this mean that Mathematica is not able to solve this type of recurrence relation? How can I change my input so that Mathematica does solve the recurrence, assuming it is possible?
equation-solving symbolic syntax recursion difference-equations
equation-solving symbolic syntax recursion difference-equations
New contributor
New contributor
edited 2 days ago
bbgodfrey
43.7k857107
43.7k857107
New contributor
asked 2 days ago
konsolas
1235
1235
New contributor
New contributor
Try replacing the next-to-last term inRSolve
(a
) witha[n]
.
– yosimitsu kodanuri
2 days ago
It still simply echoes the input:RSolve[{a[0] == 1, a[1 + 2 n] == 2 a[2 n], a[2 n] == 2 + a[-1 + 2 n]}, a[n], n]
– konsolas
2 days ago
1
Welcome to Mathematica.SE! Interesting question(+1). I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise.
– bbgodfrey
2 days ago
add a comment |
Try replacing the next-to-last term inRSolve
(a
) witha[n]
.
– yosimitsu kodanuri
2 days ago
It still simply echoes the input:RSolve[{a[0] == 1, a[1 + 2 n] == 2 a[2 n], a[2 n] == 2 + a[-1 + 2 n]}, a[n], n]
– konsolas
2 days ago
1
Welcome to Mathematica.SE! Interesting question(+1). I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise.
– bbgodfrey
2 days ago
Try replacing the next-to-last term in
RSolve
(a
) with a[n]
.– yosimitsu kodanuri
2 days ago
Try replacing the next-to-last term in
RSolve
(a
) with a[n]
.– yosimitsu kodanuri
2 days ago
It still simply echoes the input:
RSolve[{a[0] == 1, a[1 + 2 n] == 2 a[2 n], a[2 n] == 2 + a[-1 + 2 n]}, a[n], n]
– konsolas
2 days ago
It still simply echoes the input:
RSolve[{a[0] == 1, a[1 + 2 n] == 2 a[2 n], a[2 n] == 2 + a[-1 + 2 n]}, a[n], n]
– konsolas
2 days ago
1
1
Welcome to Mathematica.SE! Interesting question(+1). I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise.
– bbgodfrey
2 days ago
Welcome to Mathematica.SE! Interesting question(+1). I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise.
– bbgodfrey
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
up vote
7
down vote
accepted
It appears that RSolve
cannot solve difference equations in which two different equations describe the same variable. If so, a work-around is to represent a[k]
with k
an even index as c[k]
, and with k
an odd indix as b[k]
, so that there is only one equation per variable.
FullSimplify[RSolveValue[{c[0] == 1, b[k] == c[k - 1]*2, c[k + 2] == b[k + 1] + 2},
{c[k], b[k]}, k] /. C[1] -> 0]
(* {-2 + 3 2^(-1 + k/2) (1 + (-1)^k), -4 - 3 2^(1/2 (-1 + k)) (-1 + (-1)^k)} *)
Then, construct the desired a[k]
as even-index terms of c[k]
and odd-index terms of b[k]
.
sol[k_] := If[EvenQ[k], -2 + 3 2^(k/2) , -4 + 3 2^((1 + k)/2) ]
Table[sol[k], {k, 0, 10}]
(* {1, 2, 4, 8, 10, 20, 22, 44, 46, 92, 94} *)
as desired.
add a comment |
up vote
4
down vote
When Mathematica returns the input without any error message, it is unable to evaluate the input.
With this particular recursion there is another approach. The recursion can be defined by
Clear[a, ar]
ar[0] = 1; ar[n_?OddQ] := ar[n - 1]*2; ar[n_?EvenQ] := ar[n - 1] + 2;
Generating a sequence from this recursion
seq = ar /@ Range[10]
(* {2, 4, 8, 10, 20, 22, 44, 46, 92, 94} *)
Use FindSequenceFunction
to find the closed form of the recursion
a[n_] = FindSequenceFunction[seq, n] // FullSimplify
(* -3 + (-1)^n + 3 2^(-1 + n/2) (1 + Sqrt[2] + (-1)^(1 + n) (-1 + Sqrt[2])) *)
Checking equivalence outside of the range of seq
And @@ Table[a[n] == ar[n], {n, 0, 100}]
(* True *)
EDIT: Verifying,
Simplify[{a[2 n + 1] == a[2 n]*2,
a[2 n] == a[2 n - 1] + 2}, {Element[n, Integers], n >= 0}]
(* {True, True} *)
Hi, thanks for the alternative solution. Do you know why Mathematica was unable to evaluate the input given?
– konsolas
2 days ago
Don’t know. Presumably the algorithms used are not sufficiently robust to cover this case.
– Bob Hanlon
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
accepted
It appears that RSolve
cannot solve difference equations in which two different equations describe the same variable. If so, a work-around is to represent a[k]
with k
an even index as c[k]
, and with k
an odd indix as b[k]
, so that there is only one equation per variable.
FullSimplify[RSolveValue[{c[0] == 1, b[k] == c[k - 1]*2, c[k + 2] == b[k + 1] + 2},
{c[k], b[k]}, k] /. C[1] -> 0]
(* {-2 + 3 2^(-1 + k/2) (1 + (-1)^k), -4 - 3 2^(1/2 (-1 + k)) (-1 + (-1)^k)} *)
Then, construct the desired a[k]
as even-index terms of c[k]
and odd-index terms of b[k]
.
sol[k_] := If[EvenQ[k], -2 + 3 2^(k/2) , -4 + 3 2^((1 + k)/2) ]
Table[sol[k], {k, 0, 10}]
(* {1, 2, 4, 8, 10, 20, 22, 44, 46, 92, 94} *)
as desired.
add a comment |
up vote
7
down vote
accepted
It appears that RSolve
cannot solve difference equations in which two different equations describe the same variable. If so, a work-around is to represent a[k]
with k
an even index as c[k]
, and with k
an odd indix as b[k]
, so that there is only one equation per variable.
FullSimplify[RSolveValue[{c[0] == 1, b[k] == c[k - 1]*2, c[k + 2] == b[k + 1] + 2},
{c[k], b[k]}, k] /. C[1] -> 0]
(* {-2 + 3 2^(-1 + k/2) (1 + (-1)^k), -4 - 3 2^(1/2 (-1 + k)) (-1 + (-1)^k)} *)
Then, construct the desired a[k]
as even-index terms of c[k]
and odd-index terms of b[k]
.
sol[k_] := If[EvenQ[k], -2 + 3 2^(k/2) , -4 + 3 2^((1 + k)/2) ]
Table[sol[k], {k, 0, 10}]
(* {1, 2, 4, 8, 10, 20, 22, 44, 46, 92, 94} *)
as desired.
add a comment |
up vote
7
down vote
accepted
up vote
7
down vote
accepted
It appears that RSolve
cannot solve difference equations in which two different equations describe the same variable. If so, a work-around is to represent a[k]
with k
an even index as c[k]
, and with k
an odd indix as b[k]
, so that there is only one equation per variable.
FullSimplify[RSolveValue[{c[0] == 1, b[k] == c[k - 1]*2, c[k + 2] == b[k + 1] + 2},
{c[k], b[k]}, k] /. C[1] -> 0]
(* {-2 + 3 2^(-1 + k/2) (1 + (-1)^k), -4 - 3 2^(1/2 (-1 + k)) (-1 + (-1)^k)} *)
Then, construct the desired a[k]
as even-index terms of c[k]
and odd-index terms of b[k]
.
sol[k_] := If[EvenQ[k], -2 + 3 2^(k/2) , -4 + 3 2^((1 + k)/2) ]
Table[sol[k], {k, 0, 10}]
(* {1, 2, 4, 8, 10, 20, 22, 44, 46, 92, 94} *)
as desired.
It appears that RSolve
cannot solve difference equations in which two different equations describe the same variable. If so, a work-around is to represent a[k]
with k
an even index as c[k]
, and with k
an odd indix as b[k]
, so that there is only one equation per variable.
FullSimplify[RSolveValue[{c[0] == 1, b[k] == c[k - 1]*2, c[k + 2] == b[k + 1] + 2},
{c[k], b[k]}, k] /. C[1] -> 0]
(* {-2 + 3 2^(-1 + k/2) (1 + (-1)^k), -4 - 3 2^(1/2 (-1 + k)) (-1 + (-1)^k)} *)
Then, construct the desired a[k]
as even-index terms of c[k]
and odd-index terms of b[k]
.
sol[k_] := If[EvenQ[k], -2 + 3 2^(k/2) , -4 + 3 2^((1 + k)/2) ]
Table[sol[k], {k, 0, 10}]
(* {1, 2, 4, 8, 10, 20, 22, 44, 46, 92, 94} *)
as desired.
edited yesterday
answered 2 days ago
bbgodfrey
43.7k857107
43.7k857107
add a comment |
add a comment |
up vote
4
down vote
When Mathematica returns the input without any error message, it is unable to evaluate the input.
With this particular recursion there is another approach. The recursion can be defined by
Clear[a, ar]
ar[0] = 1; ar[n_?OddQ] := ar[n - 1]*2; ar[n_?EvenQ] := ar[n - 1] + 2;
Generating a sequence from this recursion
seq = ar /@ Range[10]
(* {2, 4, 8, 10, 20, 22, 44, 46, 92, 94} *)
Use FindSequenceFunction
to find the closed form of the recursion
a[n_] = FindSequenceFunction[seq, n] // FullSimplify
(* -3 + (-1)^n + 3 2^(-1 + n/2) (1 + Sqrt[2] + (-1)^(1 + n) (-1 + Sqrt[2])) *)
Checking equivalence outside of the range of seq
And @@ Table[a[n] == ar[n], {n, 0, 100}]
(* True *)
EDIT: Verifying,
Simplify[{a[2 n + 1] == a[2 n]*2,
a[2 n] == a[2 n - 1] + 2}, {Element[n, Integers], n >= 0}]
(* {True, True} *)
Hi, thanks for the alternative solution. Do you know why Mathematica was unable to evaluate the input given?
– konsolas
2 days ago
Don’t know. Presumably the algorithms used are not sufficiently robust to cover this case.
– Bob Hanlon
2 days ago
add a comment |
up vote
4
down vote
When Mathematica returns the input without any error message, it is unable to evaluate the input.
With this particular recursion there is another approach. The recursion can be defined by
Clear[a, ar]
ar[0] = 1; ar[n_?OddQ] := ar[n - 1]*2; ar[n_?EvenQ] := ar[n - 1] + 2;
Generating a sequence from this recursion
seq = ar /@ Range[10]
(* {2, 4, 8, 10, 20, 22, 44, 46, 92, 94} *)
Use FindSequenceFunction
to find the closed form of the recursion
a[n_] = FindSequenceFunction[seq, n] // FullSimplify
(* -3 + (-1)^n + 3 2^(-1 + n/2) (1 + Sqrt[2] + (-1)^(1 + n) (-1 + Sqrt[2])) *)
Checking equivalence outside of the range of seq
And @@ Table[a[n] == ar[n], {n, 0, 100}]
(* True *)
EDIT: Verifying,
Simplify[{a[2 n + 1] == a[2 n]*2,
a[2 n] == a[2 n - 1] + 2}, {Element[n, Integers], n >= 0}]
(* {True, True} *)
Hi, thanks for the alternative solution. Do you know why Mathematica was unable to evaluate the input given?
– konsolas
2 days ago
Don’t know. Presumably the algorithms used are not sufficiently robust to cover this case.
– Bob Hanlon
2 days ago
add a comment |
up vote
4
down vote
up vote
4
down vote
When Mathematica returns the input without any error message, it is unable to evaluate the input.
With this particular recursion there is another approach. The recursion can be defined by
Clear[a, ar]
ar[0] = 1; ar[n_?OddQ] := ar[n - 1]*2; ar[n_?EvenQ] := ar[n - 1] + 2;
Generating a sequence from this recursion
seq = ar /@ Range[10]
(* {2, 4, 8, 10, 20, 22, 44, 46, 92, 94} *)
Use FindSequenceFunction
to find the closed form of the recursion
a[n_] = FindSequenceFunction[seq, n] // FullSimplify
(* -3 + (-1)^n + 3 2^(-1 + n/2) (1 + Sqrt[2] + (-1)^(1 + n) (-1 + Sqrt[2])) *)
Checking equivalence outside of the range of seq
And @@ Table[a[n] == ar[n], {n, 0, 100}]
(* True *)
EDIT: Verifying,
Simplify[{a[2 n + 1] == a[2 n]*2,
a[2 n] == a[2 n - 1] + 2}, {Element[n, Integers], n >= 0}]
(* {True, True} *)
When Mathematica returns the input without any error message, it is unable to evaluate the input.
With this particular recursion there is another approach. The recursion can be defined by
Clear[a, ar]
ar[0] = 1; ar[n_?OddQ] := ar[n - 1]*2; ar[n_?EvenQ] := ar[n - 1] + 2;
Generating a sequence from this recursion
seq = ar /@ Range[10]
(* {2, 4, 8, 10, 20, 22, 44, 46, 92, 94} *)
Use FindSequenceFunction
to find the closed form of the recursion
a[n_] = FindSequenceFunction[seq, n] // FullSimplify
(* -3 + (-1)^n + 3 2^(-1 + n/2) (1 + Sqrt[2] + (-1)^(1 + n) (-1 + Sqrt[2])) *)
Checking equivalence outside of the range of seq
And @@ Table[a[n] == ar[n], {n, 0, 100}]
(* True *)
EDIT: Verifying,
Simplify[{a[2 n + 1] == a[2 n]*2,
a[2 n] == a[2 n - 1] + 2}, {Element[n, Integers], n >= 0}]
(* {True, True} *)
edited yesterday
answered 2 days ago
Bob Hanlon
57.9k23593
57.9k23593
Hi, thanks for the alternative solution. Do you know why Mathematica was unable to evaluate the input given?
– konsolas
2 days ago
Don’t know. Presumably the algorithms used are not sufficiently robust to cover this case.
– Bob Hanlon
2 days ago
add a comment |
Hi, thanks for the alternative solution. Do you know why Mathematica was unable to evaluate the input given?
– konsolas
2 days ago
Don’t know. Presumably the algorithms used are not sufficiently robust to cover this case.
– Bob Hanlon
2 days ago
Hi, thanks for the alternative solution. Do you know why Mathematica was unable to evaluate the input given?
– konsolas
2 days ago
Hi, thanks for the alternative solution. Do you know why Mathematica was unable to evaluate the input given?
– konsolas
2 days ago
Don’t know. Presumably the algorithms used are not sufficiently robust to cover this case.
– Bob Hanlon
2 days ago
Don’t know. Presumably the algorithms used are not sufficiently robust to cover this case.
– Bob Hanlon
2 days ago
add a comment |
konsolas is a new contributor. Be nice, and check out our Code of Conduct.
konsolas is a new contributor. Be nice, and check out our Code of Conduct.
konsolas is a new contributor. Be nice, and check out our Code of Conduct.
konsolas is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f186732%2frsolve-not-reducing-for-a-certain-recurrence-relation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try replacing the next-to-last term in
RSolve
(a
) witha[n]
.– yosimitsu kodanuri
2 days ago
It still simply echoes the input:
RSolve[{a[0] == 1, a[1 + 2 n] == 2 a[2 n], a[2 n] == 2 + a[-1 + 2 n]}, a[n], n]
– konsolas
2 days ago
1
Welcome to Mathematica.SE! Interesting question(+1). I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise.
– bbgodfrey
2 days ago