v1 = [1 2 3 4]

% An alternative
v2 = 1:4    % or v2 = 1:1:4

% General convention start:step:end
v3 = 0:2:10  % even numbers from 0 to 10

% The step can also be negative
v4 = 11:-2:1

% Multiplication by a scalar
v5 = 2*v1

% or
v6 = v1*2

% I take the square root to every element of vector
% v1
v7 = sqrt(v1)

% I compute the sin of each element of the vector
% v1
v8 = sin(v1)

% I compute the square of each element
%v9 = v1^2 it doesn't work

%{
    We are performing the same operation on all
    the elements of the vector. These kind of
    operations are called element-wise
    operations.
    For element-wise operations, I need to use
    the dot.
%}
v9 = v1.^2
v10 = v1.*2

% v1 = [1, 2, 3, 4]
% v10 = [2, 4, 6, 8]
% I want to divide each element of v1 by the
% corresponding element of v10
v11= v1./v10

% I create a 3x2 matrix on ones
A = ones(3, 2)

% I create a 2x5 matrix of zeros
B = zeros(2, 5)

% addition of vectors
u = ones(1, 4)
v12 = v1 + u

% Exercise 32 (slow way)
x1 = 1;
t1 = 1;
i1 = .07;
V1 = x1*(1 + i1)^-t1
x2 = 1;
t2 = 2;
i2 = .075;
V2 = x2*(1 + i2)^-t2

% Exercise 32 (fast way)
t = 1:4;
x = [1, 1, 1, 100];
i = [.07, .075, .065, .08];

% x*(1 + i)^-t
V = x.*(1 + i).^-t
V0 = sum(V)
D = sum(V.*t)/V0

% Exercise 33
t = 1:4;
C = [6, 6, 6, 106];
i = .055;
V = C.*(1 + i).^-t
V0 = sum(V)
D_Mac = sum(V.*t)/V0

% Exercise 34
D_mod = -1/(1 + i)*D_Mac
