a(n) = 1, 2, 3, 4, 5 in matlab

You can write a program to generate the series of numbers you want using a for loop. Here is an example code that generates the series a(n) = 1, 2, 3, 4, 5:

main.m
a = zeros(1, 5); % Pre-allocate memory for the vector
for i = 1 : 5
    a(i) = i;
end
disp(a)
94 chars
6 lines

Output:

main.m
1 2 3 4 5
10 chars
2 lines

In this code, we first create a vector of zeros with 5 elements using the zeros function. We then use a for loop to iterate over the values 1 through 5 and set the corresponding element of the vector a equal to the loop variable i. Finally, we print the resulting vector using the disp function.

related categories

gistlibby LogSnag