%% 1a

x = -5:5;

%% 1b

x(3)

%% 1c

x(3) = -1000

%% 1d

x(end)
x(11)
x(length(x))

%% 1e

x(end) = 1000

%% 1f

x(end - 1) = []

%% 1g

x = [-6 x]

%% 1h

x = [x(1:8) 1.5 x(9:end)]

%% 1i

length(x)

%% 2a

y = [50:-10:-50]'

%% 2b

y(2:2:end)

%% 2c

y(2:2:end) = y(2:2:end) + 1

%% 2d

y(1:2:end) = []

%% 3

m = [-4; 3.7; 0; 2.5; 1.2; -2.8; -1.4];
f = [-37; 38; 0; 29; 21; -21; -8];

%% 3a

X = [m ones(length(m), 1)]


%% 3b

A = X' * X

%% 3c

rows = size(A, 1)

%% 3d

cols = size(A, 2)


%% 3e

B = X .* X
sum(B)


%% 3f

y = X' * f


%% 3g

x = A \ y
x = inv(A) * y

%% 4

x = linspace(-5, 5, 175);
y = sin(pi * x) ./ (pi * x);
plot(x, y, 'b');
hold on
plot(x, cos(pi * x), 'r');
legend('sinc(x)', 'cos(pi * x)');
xlabel('x');

%% 5a

% 2311 = 2 * 4^3 + 3 * 4^2 + 1 * 4^1 + 1 * 4^0
%      = 128     + 48      + 4       + 1
%      = 181

%% 5b

% 1011 = 1 * -2^3 + 0 * 2^2 + 1 * 2^1 + 1 * 2^0
%      = -8       + 0       + 2       + 1
%      = -5

%% 5c

% pi has an infinite number of digits but there are only a finite number
% of digits in its floating point representation; therefore, we are
% computing the cosine of a number that is not quite pi / 2
%
% Presumably, there is some computation required to calculate the cosine
% of an angle; because this calculation occurs using only a finite
% number of digits, the computed cosine of pi / 2 may not be exactly
% equal to 0

%% 5d

% epsilon might be too large if x and y are small
%
% epsilon might be too small if x and y are large


%% 5e

% -inconsistent indenting
% -inconsistent spacing around operators
% -frequency variable named 'z' instead of 'f'
% -t does not have 100 equally spaced time steps; it has 101
% -variable named sin has the same name as a MATLAB function
