%% Question 5a
A = [1 3; 4 2];
B = [-1 5; -3 8];
C = [dprod(A(1, :), B(:, 1))     dprod(A(1, :), B(:, 2));
     dprod(A(2, :), B(:, 1))     dprod(A(2, :), B(:, 2))];

%% Question 5b
m = 1.5;
r = [6 6 8];
v = [-1 1 0];
L = cross(r, m * v)


%% Question 5c
g = zeros(1, 10);   % grains on square N
t = zeros(1, 10);   % total grains
n = [1:8 32 64];
[g(1), t(1)] = chessboard(1);
[g(2), t(2)] = chessboard(2);
[g(3), t(3)] = chessboard(3);
[g(4), t(4)] = chessboard(4);
[g(5), t(5)] = chessboard(5);
[g(6), t(6)] = chessboard(6);
[g(7), t(7)] = chessboard(7);
[g(8), t(8)] = chessboard(8);
[g(9), t(9)] = chessboard(32);
[g(10), t(10)] = chessboard(64);

s = sprintf('square %d\t grains %d\t total %d\n', [g; t; n]);
disp(s)


%% Question 5d
A = 2;
m = 0.5;
k = 50;
b = 0.5;
phi = pi / 4;
t = linspace(0, 10, 1000);
[x, v] = dhmotion(A, m, k, b, phi, t);
plot(t, x, 'b-', t, v, 'r-', t, -v, 'r-');
legend('displacement', 'envelope');
xlabel('time (s)');
ylabel('displacement');
title('displacement of an ideal damped harmonic oscillator');


%% Question 5e
X = load('kirkwood.csv');
hist(X, 10000);
line([2.06 2.06], [0 350])
line([2.5 2.5], [0 350])
line([2.82 2.82], [0 350])
line([2.95 2.95], [0 350])
line([3.27 3.27], [0 350])
xlabel('semi-major axis (AU)')
ylabel('number of asteroids');
title('main-belt asteroid distribution');

