%% 1a

x = -5:5;

%% 1b

x(1)

%% 1c

x(1) = 1000

%% 1d

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

%% 1e

x(end) = 1000

%% 1f

x(6) = []

%% 1g

x = [-6 x]

%% 1h

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

%% 1i

length(x)

%% 2a

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

%% 2b

y(1:2:end)

%% 2c

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

%% 2d

y(2:2:10) = []

%% 3a

A = [16 2 3 13; 5 11 10 8; 9 7 6 12]


%% 3b

rows = size(A, 1)

%% 3c

cols = size(A, 2)

%% 3d

A(2, 4)


%% 3e

A(1, :)


%% 3f

A(1, :) = [4 3 2 1]


%% 3g

A(:, 3)

%% 3h

A(4, :) = [6 7 8 9]

%% 3i

A = [A(:, 1) [1 2 3 4]' A(:, 2:end)]

%% 4

dx = linspace(-2, 2, 50);
k = 1.5;
F = k * dx;
U = 0.5 * k * (dx .* dx);
plot(dx, F, 'b');
hold on
plot(dx, U, 'r');
legend('force', 'potential');
xlabel('change in length');

%% 5a

% 2011 = 2 * 3^3 + 0 * 3^2 + 1 * 3^1 + 1 * 3^0
%      = 54      + 0       + 3       + 1
%      = 58

%% 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 sine of a number that is not quite pi
%
% Presumably, there is some computation required to calculate the sine
% of an angle; because this calculation occurs using only a finite
% number of digits, the computed sine of pi may not be exactly equal to 0

%% 5d

% -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


%% 5e

% The error occurs because the script from 5d created a variable named
% sin; the name sin now refers to the variable instead of the function
% named sin. When my script now runs, the expression 
%
% y = A * sin(2 * pi * f * t)
%
% is now trying to index into the variable named sin using a non-integer
% index.