RecurrenceTable involving inputs from a vector
$begingroup$
Directly going to the issue, my problem is how to use a RecurrenceTable
when it have inputs from a vector defined previously. For instance I have:
p={1,10,100,1000,10000};
And the recursive relation I want to solve is:
RecurrenceTable[{a[n + 1] == 2 a[n] + p[[n]], a[1] == 1}, a, {n, 1, 5}]
which must have an answer as:
{1,3,16,132,1264}
But I face with this error:
Part::pkspec1: The expression n cannot be used as a part specification.
Part::pkspec1: The expression #1 cannot be used as a part specification.
For avoiding part specification I tried the following:
z = 1;
RecurrenceTable[{a[n + 1] == 2 a[n] + p[[z++]], a[1] == 1}, a, {n, 1, 5}]
But the answer is wrong:
{1, 3, 7, 15, 31}
recursion vector
$endgroup$
add a comment |
$begingroup$
Directly going to the issue, my problem is how to use a RecurrenceTable
when it have inputs from a vector defined previously. For instance I have:
p={1,10,100,1000,10000};
And the recursive relation I want to solve is:
RecurrenceTable[{a[n + 1] == 2 a[n] + p[[n]], a[1] == 1}, a, {n, 1, 5}]
which must have an answer as:
{1,3,16,132,1264}
But I face with this error:
Part::pkspec1: The expression n cannot be used as a part specification.
Part::pkspec1: The expression #1 cannot be used as a part specification.
For avoiding part specification I tried the following:
z = 1;
RecurrenceTable[{a[n + 1] == 2 a[n] + p[[z++]], a[1] == 1}, a, {n, 1, 5}]
But the answer is wrong:
{1, 3, 7, 15, 31}
recursion vector
$endgroup$
$begingroup$
Related: (14645)
$endgroup$
– Mr.Wizard♦
4 hours ago
add a comment |
$begingroup$
Directly going to the issue, my problem is how to use a RecurrenceTable
when it have inputs from a vector defined previously. For instance I have:
p={1,10,100,1000,10000};
And the recursive relation I want to solve is:
RecurrenceTable[{a[n + 1] == 2 a[n] + p[[n]], a[1] == 1}, a, {n, 1, 5}]
which must have an answer as:
{1,3,16,132,1264}
But I face with this error:
Part::pkspec1: The expression n cannot be used as a part specification.
Part::pkspec1: The expression #1 cannot be used as a part specification.
For avoiding part specification I tried the following:
z = 1;
RecurrenceTable[{a[n + 1] == 2 a[n] + p[[z++]], a[1] == 1}, a, {n, 1, 5}]
But the answer is wrong:
{1, 3, 7, 15, 31}
recursion vector
$endgroup$
Directly going to the issue, my problem is how to use a RecurrenceTable
when it have inputs from a vector defined previously. For instance I have:
p={1,10,100,1000,10000};
And the recursive relation I want to solve is:
RecurrenceTable[{a[n + 1] == 2 a[n] + p[[n]], a[1] == 1}, a, {n, 1, 5}]
which must have an answer as:
{1,3,16,132,1264}
But I face with this error:
Part::pkspec1: The expression n cannot be used as a part specification.
Part::pkspec1: The expression #1 cannot be used as a part specification.
For avoiding part specification I tried the following:
z = 1;
RecurrenceTable[{a[n + 1] == 2 a[n] + p[[z++]], a[1] == 1}, a, {n, 1, 5}]
But the answer is wrong:
{1, 3, 7, 15, 31}
recursion vector
recursion vector
asked 5 hours ago
Reza FarajiReza Faraji
132
132
$begingroup$
Related: (14645)
$endgroup$
– Mr.Wizard♦
4 hours ago
add a comment |
$begingroup$
Related: (14645)
$endgroup$
– Mr.Wizard♦
4 hours ago
$begingroup$
Related: (14645)
$endgroup$
– Mr.Wizard♦
4 hours ago
$begingroup$
Related: (14645)
$endgroup$
– Mr.Wizard♦
4 hours ago
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
Try Indexed
:
p = {1, 10, 100, 1000, 10000};
RecurrenceTable[{a[n + 1] == 2 a[n] + Indexed[p, n], a[1] == 1}, a, {n, 1, 5}]
{1, 3, 16, 132, 1264}
Alternatives:
RecurrenceTable[{a[n + 1] == 2 a[n] + Unevaluated[p[[n]]], a[1] == 1}, a, {n, 1, 5}]
{1, 3, 16, 132, 1264}
part[x_, n_Integer] := x[[n]]
RecurrenceTable[{a[n + 1] == 2 a[n] + part[p, n], a[1] == 1}, a, {n, 1, 5}]
{1, 3, 16, 132, 1264}
Of course you could just Quiet
the error and ignore it:
RecurrenceTable[{a[n + 1] == 2 a[n] + p[[n]], a[1] == 1}, a, {n, 1, 5}] // Quiet
{1, 3, 16, 132, 1264}
$endgroup$
$begingroup$
Thanks a bunch @Mr.Wizard♦
$endgroup$
– Reza Faraji
4 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f197178%2frecurrencetable-involving-inputs-from-a-vector%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Try Indexed
:
p = {1, 10, 100, 1000, 10000};
RecurrenceTable[{a[n + 1] == 2 a[n] + Indexed[p, n], a[1] == 1}, a, {n, 1, 5}]
{1, 3, 16, 132, 1264}
Alternatives:
RecurrenceTable[{a[n + 1] == 2 a[n] + Unevaluated[p[[n]]], a[1] == 1}, a, {n, 1, 5}]
{1, 3, 16, 132, 1264}
part[x_, n_Integer] := x[[n]]
RecurrenceTable[{a[n + 1] == 2 a[n] + part[p, n], a[1] == 1}, a, {n, 1, 5}]
{1, 3, 16, 132, 1264}
Of course you could just Quiet
the error and ignore it:
RecurrenceTable[{a[n + 1] == 2 a[n] + p[[n]], a[1] == 1}, a, {n, 1, 5}] // Quiet
{1, 3, 16, 132, 1264}
$endgroup$
$begingroup$
Thanks a bunch @Mr.Wizard♦
$endgroup$
– Reza Faraji
4 hours ago
add a comment |
$begingroup$
Try Indexed
:
p = {1, 10, 100, 1000, 10000};
RecurrenceTable[{a[n + 1] == 2 a[n] + Indexed[p, n], a[1] == 1}, a, {n, 1, 5}]
{1, 3, 16, 132, 1264}
Alternatives:
RecurrenceTable[{a[n + 1] == 2 a[n] + Unevaluated[p[[n]]], a[1] == 1}, a, {n, 1, 5}]
{1, 3, 16, 132, 1264}
part[x_, n_Integer] := x[[n]]
RecurrenceTable[{a[n + 1] == 2 a[n] + part[p, n], a[1] == 1}, a, {n, 1, 5}]
{1, 3, 16, 132, 1264}
Of course you could just Quiet
the error and ignore it:
RecurrenceTable[{a[n + 1] == 2 a[n] + p[[n]], a[1] == 1}, a, {n, 1, 5}] // Quiet
{1, 3, 16, 132, 1264}
$endgroup$
$begingroup$
Thanks a bunch @Mr.Wizard♦
$endgroup$
– Reza Faraji
4 hours ago
add a comment |
$begingroup$
Try Indexed
:
p = {1, 10, 100, 1000, 10000};
RecurrenceTable[{a[n + 1] == 2 a[n] + Indexed[p, n], a[1] == 1}, a, {n, 1, 5}]
{1, 3, 16, 132, 1264}
Alternatives:
RecurrenceTable[{a[n + 1] == 2 a[n] + Unevaluated[p[[n]]], a[1] == 1}, a, {n, 1, 5}]
{1, 3, 16, 132, 1264}
part[x_, n_Integer] := x[[n]]
RecurrenceTable[{a[n + 1] == 2 a[n] + part[p, n], a[1] == 1}, a, {n, 1, 5}]
{1, 3, 16, 132, 1264}
Of course you could just Quiet
the error and ignore it:
RecurrenceTable[{a[n + 1] == 2 a[n] + p[[n]], a[1] == 1}, a, {n, 1, 5}] // Quiet
{1, 3, 16, 132, 1264}
$endgroup$
Try Indexed
:
p = {1, 10, 100, 1000, 10000};
RecurrenceTable[{a[n + 1] == 2 a[n] + Indexed[p, n], a[1] == 1}, a, {n, 1, 5}]
{1, 3, 16, 132, 1264}
Alternatives:
RecurrenceTable[{a[n + 1] == 2 a[n] + Unevaluated[p[[n]]], a[1] == 1}, a, {n, 1, 5}]
{1, 3, 16, 132, 1264}
part[x_, n_Integer] := x[[n]]
RecurrenceTable[{a[n + 1] == 2 a[n] + part[p, n], a[1] == 1}, a, {n, 1, 5}]
{1, 3, 16, 132, 1264}
Of course you could just Quiet
the error and ignore it:
RecurrenceTable[{a[n + 1] == 2 a[n] + p[[n]], a[1] == 1}, a, {n, 1, 5}] // Quiet
{1, 3, 16, 132, 1264}
answered 4 hours ago
Mr.Wizard♦Mr.Wizard
233k294791067
233k294791067
$begingroup$
Thanks a bunch @Mr.Wizard♦
$endgroup$
– Reza Faraji
4 hours ago
add a comment |
$begingroup$
Thanks a bunch @Mr.Wizard♦
$endgroup$
– Reza Faraji
4 hours ago
$begingroup$
Thanks a bunch @Mr.Wizard♦
$endgroup$
– Reza Faraji
4 hours ago
$begingroup$
Thanks a bunch @Mr.Wizard♦
$endgroup$
– Reza Faraji
4 hours ago
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
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%2f197178%2frecurrencetable-involving-inputs-from-a-vector%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
$begingroup$
Related: (14645)
$endgroup$
– Mr.Wizard♦
4 hours ago