필터 지우기
필터 지우기

Array that contains a geometric series

조회 수: 15 (최근 30일)
shir shalom
shir shalom 2016년 12월 19일
댓글: shir shalom 2016년 12월 20일
Hi, Is there a short way to create an array in which the elements are making a geometric series?
like for example the following array:
x=[1 2 4 8 16 32 64]
Thanks, Shir

채택된 답변

Roger Stafford
Roger Stafford 2016년 12월 19일
A general form for a geometric series is:
[a,a*r,a*r^2,a*r^3,...]
You can generate n of these by:
s = a*r.^(0:n-1);
  댓글 수: 1
shir shalom
shir shalom 2016년 12월 20일
Thank you! that's a great general solution.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

John D'Errico
John D'Errico 2016년 12월 19일
  댓글 수: 3
John D'Errico
John D'Errico 2016년 12월 19일
You could have said that the first time. But what is wrong then with this?
2.^(-1:6)
It really won't work? I guess I need to learn this new math then.
Or, for a more general form, with some other start point:
0.1*2.^(0:6)
Could I have used a loop? Of course. But why? Learn to use Matlab.
shir shalom
shir shalom 2016년 12월 20일
Yes, sorry of course it works. I guess I was too tired to think last night. Thanks alot!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by