Let $\sum_{n=1}^\infty \frac{a_n}{3^n}.$ Determine (numerically or not) the limit of the infinite series by choosing $a_n=0$ or $2$ randomly.

188 Views Asked by At

This is a follow up question to Let $\sum_{n=1}^\infty \frac{a_n}{3^n}.$ Determine (numerically or not) the limit of the infinite series by choosing $a_n=0$ or $2$ randomly.

From that question I received help in choosing randomly from the set $\{0,2\}$. Now I'm attempting to implement the code with the sum and I'm familiar with the symsum command, but it's giving an error.

My Matlab code is:

r = randi([1 2],1000,1)
r(find(r==1))=0
syms n
u = symsum(r(n)/(2^(n-1)),n,1,1000)
ans    

What's weird is if I just run,

u = symsum(1/(2^(n-1)),n,1,1000)

I get a huge number, but if I do

u = symsum(1/(2^(n-1)),n,1,inf)

it outputs the right number. Is there something I'm missing about the symsum function?

I figure what I wrote above should make sense since the indexing on the vector I make with the randi function is the same indexing on the sum. Am I even using the right function to begin with?

Thanks for any help or feedback!

1

There are 1 best solutions below

3
On BEST ANSWER

Look at the error message Matlab gives you, we have

Indexing input must be numeric, logical or ':'.

So: No indexing with symbolic variables. If you want to evaluate it for your $r_n$, just do

sum(r .* 2.^(-(0:length(r)-1)'));

That does the trick. Regarding your second question, what Matlab tells you is: $$ \sum_{k=0}^{999} \frac 1{2^k} = \frac{ 107150860718626732094842504906000181056140481170553360744375\\ \ \ 038837035105112493612249319837881569585812759467291755314682\\\ \ \ 518714528569231404359845775746985748039345677748242309854210\\ \ \ \ \ 746050623711418779541821530464749835819412673987675591655439\\ \ \ \ \ \ 46077062914571196477686542167660429831652624386837205668069375}{535754303593133660474212524530000905280702405852766803721875\\ \ \ 194185175525562468061246599189407847929063797336458776573412\\ \ \ \ 593572642846157021799228878734928740196728388741211549271053\\ \ \ \ \ 730253118557093897709107652323749179097063369938377958277197\\ \ \ \ \ \ 3038531457285598238843271083830214915826312193418602834034688} $$ That's not a big number, just look for the / in the answer.