how to write a geometric series in command window
Show older comments
How do I write a vector that follows the geometric form: 1, 3, 6, 9...
10 Comments
"how to write a geometric series in command window... How do I write a vector that follows the geometric form: 1, 3, 6, 9..."
1,3,6,9 is not a geometric sequence.
A geometric sequence is defined as having a constant ratio between adjacent terms. The ratio of those terms is not constant.
Which of these sequences do you want?: https://oeis.org/search?q=1%2C+3%2C+6%2C+9
Sami Ahmed
on 8 Sep 2022
Have a look at specifying the step size:
3:3:10
The 1 at the start does not fit any obvious sequence.
Sami Ahmed
on 8 Sep 2022
Stephen23
on 8 Sep 2022
"how can i add one to the beginning of a vector?"
[1,yourVector]
Very basic MATLAB concepts, such as how to concatenate scalars and vectors together, are more efficiently learned by doing the introductory tutorials: https://www.mathworks.com/help/matlab/getting-started-with-matlab.html
Sami Ahmed
on 8 Sep 2022
Just calculate:
100*3 = 300
so
b = 1./(3:3:300);
numel(b)
Note that 1 + 1/3 + 1/6 + 1/9 + ... is not a geometric series.
Sami Ahmed
on 8 Sep 2022
Torsten
on 8 Sep 2022
But note that you need 1 as first term followed by 99 terms of the form 1/(3*i).
1./(3:3:300) gives 100 terms of the form 1/(3*i).
Answers (2)
a = 1 ;
r = 2 ;
n = 0:9 ;
gp = a*r.^n
4 Comments
Sami Ahmed
on 8 Sep 2022
Maybe you mean this?
a = 1 ;
r = 3 ;
n = 0:9 ;
gp = a*r.^n
Sami Ahmed
on 8 Sep 2022
Torsten
on 8 Sep 2022
This is not a geometric sequence.
For a geometric sequence, the quotient of two subsequent members of the sequence must be constant:
a(n+1)/a(n) = q = const. for every n.
In your case:
a2/a1 = 3
a3/a4 = 2
a5/a4 = 1.5
so the quotient is always different.
sum(1./[1,3:3:297])
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
