RecurrenceTable involving inputs from a vectorPrevent Part[] from trying to extract parts of symbolic...

a sore throat vs a strep throat vs strep throat

Don’t seats that recline flat defeat the purpose of having seatbelts?

How do I reattach a shelf to the wall when it ripped out of the wall?

How can Republicans who favour free markets, consistently express anger when they don't like the outcome of that choice?

Why does Mind Blank stop the Feeblemind spell?

How come there are so many candidates for the 2020 Democratic party presidential nomination?

How to limit Drive Letters Windows assigns to new removable USB drives

Which big number is bigger?

Symbolic Multivariate Distribution

A coin is thrown until the tail is above.

What's the name of these pliers?

Disappearing left side of `aligned`

What makes accurate emulation of old systems a difficult task?

TIKZ - changing one block into parallel multiple blocks

Why was the Spitfire's elliptical wing almost uncopied by other aircraft of World War 2?

Is there an official tutorial for installing Ubuntu 18.04+ on a device with an SSD and an additional internal hard drive?

Can we say “you can pay when the order gets ready”?

Critique of timeline aesthetic

Contradiction proof for inequality of P and NP?

As an international instructor, should I openly talk about my accent?

Why was Germany not as successful as other Europeans in establishing overseas colonies?

Is this homebrew Wind Wave spell balanced?

The Defining Moment

How much cash can I safely carry into the USA and avoid civil forfeiture?



RecurrenceTable involving inputs from a vector


Prevent Part[] from trying to extract parts of symbolic expressionsHow can I solve a difference-differential equation?Can RecurrenceTable make use of CompiledFunction?RecurrenceTable with vectorCompile issues, scoping and order of evaluationBasis for the intersection of vector spacesNDSolve mixing many scalar and vector equationsmultiplication of vector spacesset of recursive equations with derivativesVector and matrix use in RecurrenceTableAssociate a unique real number to any n-dimensional 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

Щит и меч (фильм) Содержание Названия серий | Сюжет |...

Венесуэла на летних Олимпийских играх 2000 Содержание Состав...

Meter-Bus Содержание Параметры шины | Стандартизация |...