% Assignment 1 - getting to know variables and expressions
%
% Nigel Stepp
%
% This one will be really easy, but it provides a good base
% for what will come next.
%
% Topics covered: expressions, matlab matirx notation, constants,
% variables, structures, arrays of structures.
% Question 1:
% Write an expression for the area of a 10 cm radius circle
% with a 3 cm radius circle cut out of it.
pi*(10)^2 - pi*(3)^2
% Question 2:
% The rotation matrix that will rotate a 2D vector by
% 90 degrees (counter-clockwise) is:
% ( 0 -1 )
% ( 1 0 )
%
% Write an expression that will rotate your favorite
% 2D vector by 90 degrees.
% (Note: Applying a rotation matrix to a vector is
% the same as multiplying the matrix and
% vector together.)
[0,-1;1,0] * [1;0]
% Question 3:
% A group of jugglers has (among others) the following
% properties:
% Name
% Prefers torches over knives
% Number of objects able to juggle
%
% Bob prefers torches, and can juggle 5 objects.
% Alice does not prefer torches, and can juggle 7 objects.
%
% 3.1: Create stucts for Alice and Bob. Save them as separate
% variables. (Please use the same field names for both)
bob.name = 'Bob';
bob.torches = true;
bob.objects = 5;
% You can also do this:
% bob = struct('name','Bob','torches',true,'objects',5)
alice.name = 'Alice';
alice.torches = false;
alice.objects = 7;
% Likewise, the one liner is:
% alice = struct('name','Alice','torches',false,'objects',7)
% 3.2: Having two separate variables could get a little annoying.
% Create a two element array named 'jugglers' that contains
% the preceding information for Alice and Bob.
jugglers = [bob alice];
% 3.3: If both Alice and Bob were juggling as many things as possible,
% how many objects would they be juggling?
% Write an expression to calculate this number using the array
% from 3.2.
jugglers(1).objects + jugglers(2).objects