%% Example: symbolic manipulation in a cross product proof
% We claimed that $a x b = |a||b|sin \theta$.  Here is the algebra of
% the proof, done using symbolic manipulation.  You'll need either
% Matlab's Symbolic Math Toolbox or Octave's Symbolic package.

syms a1 a2 a3 b1 b2 b3 real

% two vectors
a = [a1; a2; a3];
b = [b1; b2; b3];

% consider E = |a x b|^2
c = cross(a, b);
E = dot(c, c)

E = expand(E)

% hmmm, looking at those terms, some look like:
expand( dot(a,a) * dot(b,b) )

% so subtract that from E
bit = E - expand( dot(a,a) * dot(b,b) )

% and note the bit that is left...
factor(bit)
% is just:
-(dot(a,b))^2

% so make E2
E2 = dot(a,a)*dot(b,b) - (dot(a,b))^2
% and check E2 is same as the original E
should_be_zero = simplify(E2 - E)

% So LHS and RHS are the same, now take square roots and we're done.
