an array that goes down by a factor of 1/2 with each step in matlab

You can create a geometric progression by setting the first element of the array and defining the factor you want to decrease by in each step. Then loop over the desired number of steps to fill the rest of the array.

Here's an example code:

main.m
% Define the starting element and the factor
start = 1;
fact = 1/2;

% Define the length of the array
n = 10;

% Initialize the array with the starting element
x = zeros(1,n);
x(1) = start;

% Loop over the remaining elements and calculate each value
for i = 2:n
    x(i) = fact*x(i-1);
end

% Display the resulting array
disp(x)
330 chars
19 lines

This will output an array with 10 elements, where each element is half of the previous element. You can adjust the starting element (start), the factor (fact), and the length of the array (n) to fit your specific needs.

gistlibby LogSnag