One particular construct I find super elegant in mathematics is transformation matrices used in visualising geometry and inverse kinematics. These matrices are almost like magic. You can combine a sequence of transform operations into a single matrix and get the correct result in a single operation.
I have always like the matrix equation A*x=b or x = A
inv*b. For some reason, I prefer this approach to solving simultaneous linear equations.
Here's a simple 6x6 matrix problem that I would not care to solve by hand.
% A football stadium has a capacity of 100,000 attendees
% Ticket prices:
% Student = $25
% Alumni = $40
% Faculty = $60
% Public = $70
% Veterans = $32
% Guests = $ 0
% A full capacity game netted $4,987,000
% Let S = number of students, A = number of alumni, F = number of faculty
% P = number of public, V = number of veterans, G = number of guests
% S A F P V G = value
M = [ 1 1 1 1 1 1 100000; ... % total number of attendees
25 40 60 70 32 0 4897000; ... % total revenue
0 1 -1 0 0 0 11000; ... % 11000 more alumni than faculty
0 1 0 1 -10 0 0; ... % public + alumni = 10 * veterans
-1 1 1 0 0 0 0; ... % alumni + faculty = students
1 0 1 0 -4 -4 0]; % faculty + students = 4 (guests + veterans)
A = M(:,1:6); % extract 6x6 matrix
B = M(:,7); % extract value column vector
P = M(2,1:6); % ticket price by attendee type
R = inv(A)*B; % compute number of attendees by type
T = sum(R); % check total attendees = 100,000 CHECK
U = P*R; % total revenue = 4,897,000 CHECK
V = R'.*P; % revenue by attendee type - transpose R from 6x1 to 1x6
% then do element by element multiplication
%
% fancy output, all previous default output semicoloned
%
label = {'Students' 'Alumni' 'Faculty' 'Public' 'Veterans' 'Guests'};
for i = 1:6
fprintf('%-8s%7d @ %2d = %7d\n',string(label(i)),...
round(R(i)),...
M(2,i),...
round(V(i)))
end
fprintf('\nTotals %6d %8d\n',round(T), round(U))
[/font]
Results:
Students 25000 @ 25 = 625000
Alumni 18000 @ 40 = 720000
Faculty 7000 @ 60 = 420000
Public 42000 @ 70 = 2940000
Veterans 6000 @ 32 = 192000
Guests 2000 @ 0 = 0
Totals 100000 4897000
[/font]
BTW, the code is written for MATLAB and works in Octave as well. Octave is free!