RecurrenceTable involving inputs from a vector












2












$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}











share|improve this question









$endgroup$












  • $begingroup$
    Related: (14645)
    $endgroup$
    – Mr.Wizard
    4 hours ago
















2












$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}











share|improve this question









$endgroup$












  • $begingroup$
    Related: (14645)
    $endgroup$
    – Mr.Wizard
    4 hours ago














2












2








2





$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}











share|improve this question









$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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 5 hours ago









Reza FarajiReza Faraji

132




132












  • $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




$begingroup$
Related: (14645)
$endgroup$
– Mr.Wizard
4 hours ago










1 Answer
1






active

oldest

votes


















2












$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}






share|improve this answer









$endgroup$













  • $begingroup$
    Thanks a bunch @Mr.Wizard♦
    $endgroup$
    – Reza Faraji
    4 hours ago












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
});


}
});














draft saved

draft discarded


















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









2












$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}






share|improve this answer









$endgroup$













  • $begingroup$
    Thanks a bunch @Mr.Wizard♦
    $endgroup$
    – Reza Faraji
    4 hours ago
















2












$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}






share|improve this answer









$endgroup$













  • $begingroup$
    Thanks a bunch @Mr.Wizard♦
    $endgroup$
    – Reza Faraji
    4 hours ago














2












2








2





$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}






share|improve this answer









$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}







share|improve this answer












share|improve this answer



share|improve this answer










answered 4 hours ago









Mr.WizardMr.Wizard

233k294791067




233k294791067












  • $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




$begingroup$
Thanks a bunch @Mr.Wizard♦
$endgroup$
– Reza Faraji
4 hours ago


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Bundesstraße 106

Verónica Boquete

Ida-Boy-Ed-Garten