필터 지우기
필터 지우기

Write MATLAB code to create and print a vector GS that stores the first 10 terms of the geometric sequence that halves each time: {1/2, 1/4, 1/8, 1/16, ... 1/1024 }

조회 수: 9 (최근 30일)
this is what i have done but it is wrong
Initial=input('Enter initial value: ')
for i =1:10
y(i)=(Initial)*(0.5)
end

답변 (3개)

Walter Roberson
Walter Roberson 2015년 12월 2일
The problem requires that you name the variable GS. Also the question does not ask you to prompt for an initial value.
For a geometric sequence so always be multiplying the previous value by the multiplier, not the initial value.

Stephen23
Stephen23 2015년 12월 2일
편집: Stephen23 2015년 12월 2일
>> 1./pow2(1:10)
ans = 0.5 0.25 0.125 0.0625 0.03125 0.015625 0.0078125 0.0039062 0.0019531 0.00097656

Thorsten
Thorsten 2015년 12월 2일
Initial=input('Enter initial value: ')
y(1) = Initial*0.5;
for i = 2:10
y(i)= y(i-1)*0.5
end
or following Stephens suggestion, without a loop
y = Initial./pow2(1:10);
or
y = Initial./cumprod([repmat(2, 1, 10)])
or
y = Initial./2.^(1:10);

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by