Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB MATLAB question-sum of sequence

  1. Oct 1, 2011 #1
    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:

    [itex]\sum 2^{i}= 500 000[/itex]

    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.

    [itex]\sum_{i=0}^n 2^{i}= 500 000[/itex]
    Last edited: Oct 1, 2011
  2. jcsd
  3. Oct 1, 2011 #2


    User Avatar
    Science Advisor

    The sum (geometric series) is 2n+1 - 1. You can find the nearest n using logs.
  4. Oct 1, 2011 #3
    Thank you.

    Anybody on the MATLAB thing yet?
  5. Oct 2, 2011 #4


    User Avatar
    Science Advisor

    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:
    Last edited by a moderator: May 5, 2017
  6. Oct 3, 2011 #5
    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
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook