# MATLAB MATLAB question-sum of sequence

1. Oct 1, 2011

### Bassalisk

So the problem is here:

And I understand the answer and all, but I want to go further. MATLAB will be main tool for upcoming years so I have to learn.

I want to plot this:

$\sum 2^{i}= 500 000$

where sum goes from i=0 to n. n are number of iterations i am looking for.

First how can make a combination of functions, that plots a sum. Next how can I plot that so its discreet, and only exists for 1 2 3 4...

So my graph contain x axis which will be representing "i".

And my y axis should represent the value of the sum. Ergo 1 3 7 15 etc. All up to something close to 500 000(I think this will come close to like 19 iterations)

EDIT: Can anybody show me purely mathematical way to solve the problem stated in the provided post.

$\sum_{i=0}^n 2^{i}= 500 000$

Last edited: Oct 1, 2011
2. Oct 1, 2011

### mathman

The sum (geometric series) is 2n+1 - 1. You can find the nearest n using logs.

3. Oct 1, 2011

### Bassalisk

Thank you.

Anybody on the MATLAB thing yet?

4. Oct 2, 2011

### MATLABdude

Here you go:
http://www.mathworks.com/help/techdoc/learn_matlab/f3-27853.html [Broken]

While you could plot discrete points (see above), if you're going to span a large number of iterations (say, between 1 and 10,000), you should probably just plot a continuous (log) graph.

Now, as for a way to implement the summation, you should probably just a for loop. I'd start with your n_vector, make a twotothen_vector, and then use the for loop to sum. HINT: you do not need to sum from the first entry every single time. If none of these concepts makes sense, I'd start with an introductory programming book.

Implementation is left as an exercise to the reader / poster, following completion of the MATLAB getting started tutorial:
http://www.mathworks.com/help/techdoc/learn_matlab/bqr_2pl.html

Last edited by a moderator: May 5, 2017
5. Oct 3, 2011

### Bassalisk

Thank you! I will try this out. My next few year will be, literally LIVING on MATLAB. Expect more inquires from me. I am determined to get as best as i can in MATLAB.

Last edited by a moderator: May 5, 2017