%% Exercise 1 
v = 2 .* rand(1,10); % uniformly distributed on [a,b]  x = a+(b-a).*rand(m,n)
a = 16 + v;
b = v;
for i = 1:2:10
    b(i) = v(i) + 3;
end
c = sqrt(v);
d = v.^2;

%% Exercise 2
x = zeros(1,100);
for i = 1:100
    x(i) = (-1)^(i+1)/(2*i-1);
end
y = sum(x);

%% Exercise 3
t = 1790:2000;
p = 197273000 ./ (1+exp((-0.0313)*(t-1913.25)));
plot(t,p)
title('growth of the US population from 1790 to 2000')
xlabel('date (AD years)')
p_2021 = 197273000 / (1+exp((-0.0313)*(2021-1913.25)));

%% Exercise 4
X = rand(5,4); % rand(M,N), you can set M and N to any integers you want 
[m,n] = size(X);    % get the row number and the column number of the matrix
% use a for loop to move through the array element by element.
for i = 1:m        
    for j = 1:n
        if X(i,j)<0.2
            X(i,j) = 0;
        else
            X(i,j) = 1;
        end
    end
end
% NB: Because we use the function rand(), the result is likely to be different each time we run this piece of code. 

%% Exercise 5
% The function named Fibonacci is created in another M-file with the same name, so we can call this function directly here.
% NB:if we want to call the Fibonacci directly, we need to change the current folder to the path which we save the Fibonacci function.
% We can use the command "cd + file path" to change the current folder to the one we want.
% A Fibonacci sequence is defined as follow:
% The first two numbers are 0 and 1.The ith number is the sum of (i-1)th number and (i-2)th number.
n = 5; % We can make n equal to any positive integer.
Fibonacci(n) % We can call the Fibonacci function directly here if the M-file named Fibonacci is in the current folder.



