how to write a geometric series in command window

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
the sequence must continue to 100(102), i understand that it is not a geometric sequence. my assignment is asking me to write the vector 1, 3, 6, 9
Have a look at specifying the step size:
3:3:10
ans = 1×3
3 6 9
The 1 at the start does not fit any obvious sequence.
how can i add one to the beginning of a vector?
"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
sorry i understood that, now i mean to ask how can i make a vector n terms long. i want to make this vector 100 terms long...
Just calculate:
100*3 = 300
so
b = 1./(3:3:300);
numel(b)
ans = 100
Note that 1 + 1/3 + 1/6 + 1/9 + ... is not a geometric series.
ya ive got that thanks
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).

Sign in to comment.

Answers (2)

a = 1 ;
r = 2 ;
n = 0:9 ;
gp = a*r.^n
gp = 1×10
1 2 4 8 16 32 64 128 256 512

4 Comments

Maybe you mean this?
a = 1 ;
r = 3 ;
n = 0:9 ;
gp = a*r.^n
gp = 1×10
1 3 9 27 81 243 729 2187 6561 19683
i really dont know, my assignment is asking to create the vector: 1, 3, 6, 9
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.

Sign in to comment.

Categories

Products

Release

R2022a

Asked:

on 8 Sep 2022

Answered:

on 8 Sep 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!