MATLAB question-sum of sequence

  • Context: MATLAB 
  • Thread starter Thread starter Bassalisk
  • Start date Start date
  • Tags Tags
    Matlab Sequence
Click For Summary

Discussion Overview

The discussion revolves around a MATLAB programming question related to plotting the sum of a geometric series, specifically the sum \(\sum_{i=0}^n 2^{i}\) and determining the number of iterations \(n\) required for the sum to approach 500,000. Participants explore both the mathematical formulation and the implementation in MATLAB.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant seeks to plot the sum of the series and asks for guidance on how to implement this in MATLAB.
  • Another participant suggests that the sum can be expressed as \(2^{n+1} - 1\) and mentions using logarithms to find the nearest \(n\).
  • There is a suggestion to use a for loop in MATLAB to compute the sum iteratively, along with a recommendation to plot discrete points or a continuous graph depending on the range of iterations.
  • Participants discuss the potential need for introductory programming resources for those unfamiliar with MATLAB concepts.

Areas of Agreement / Disagreement

Participants generally agree on the mathematical formulation of the sum and the use of MATLAB for implementation, but there is no consensus on the best approach to plotting or the specifics of the implementation.

Contextual Notes

Some participants mention the need for a continuous graph when spanning a large number of iterations, while others focus on discrete plotting. The discussion does not resolve the best method for implementation or the specifics of the MATLAB code.

Who May Find This Useful

This discussion may be useful for individuals learning MATLAB, particularly those interested in mathematical programming and plotting geometric series.

Bassalisk
Messages
946
Reaction score
2
So the problem is here:

https://www.physicsforums.com/showthread.php?p=3532161&posted=1#post3532161

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:
Physics news on Phys.org
The sum (geometric series) is 2n+1 - 1. You can find the nearest n using logs.
 
mathman said:
The sum (geometric series) is 2n+1 - 1. You can find the nearest n using logs.

Thank you.

Anybody on the MATLAB thing yet?
 
Bassalisk said:
Thank you.

Anybody on the MATLAB thing yet?

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

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:
MATLABdude said:
Here you go:
http://www.mathworks.com/help/techdoc/learn_matlab/f3-27853.html

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

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:

Similar threads

  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K