MATLAB-infinity vectors.

55 Views Asked by At

I start learning to use Matlab. And I don't know how to create vectors:

1) $1,1/2,1/3,1/4....$

2) $0, 1,2, 2/3, 3/4...$

1

There are 1 best solutions below

0
On

You cannot create infinitely long vectors in MATLAB (or any other programming language that I am aware of). Note that the computer needs to be able to represent all the elements in that vector in its memory, and that memory is finite.

You could represent a truncated version of the vector as follows:

n = 10; % Make this number (almost) as large as you like
vectorOne = 1./(1:n);
vectorTwo = [0 1 2 2/3 3/4]; % I'm not sure how your series continues
vectorThree = [0 1 2 (2:n-1)./(3:n)];