% Jake Bobowski
% June 6, 2016
% Created using MATLAB R2014a

clearvars

% Lists are created using square brackets.
xData=[1,2,5,12,-3,3.4,pi,19,-12]

% You can use 'length' to check the number of elements in a list.

length(xData)

% Here's another list.
yData=[2,3,4,5,5,4,3,2,4];
length(yData);

% A list can be transposed (from a row to a column and vise-versa) using
% the ' notation as follows:
xColumn = xData'
xRow = xColumn'

% A specific element of a list can be selected using ().
xData(3)

% Here's how to select a multiple values and a range of values:
xData([2,4,7])
xSubset = xData(3:7)

% All of these operations work for the column data too.  Here's how to
% select the elements from 4 to the end of the list:
xColumn(4:length(xColumn))

% If you try to square a list, as in xData^2, you'll get an error.  The
% error occurs because the square of a list is ambiguous.  You might mean
% 'make a new list where each of it's elements is the square of the
% elements in the original list', or you might mean 'take the dot product of
% xData with itself where each elements of the list is like a component of
% an N-dimensional vector (assuming the xData has N elements)', or you
% might mean something like a cross product.

% There are two ways to do an element-by-element square.  The first uses
% the 'power' command and the second using the '.' notation before the
% operator.
xSquare = power(xData,2)
xSquare = xData.^2

% Of course it works for other power too.
power(xData,3.4)
xData.^-2.3

% If you have a pair of lists of equal lengths, the '.' notation can be
% used for element-by-elemnet products and quotients.

list1 = [1,3,45,5,-4.3,-2];
list2 = [-3,3.33,4.1,-1.2,-0.85,1];
length(list1)
length(list2)

% Element-by-element product:
list1.*list2

% Element-by-element quotient:
list1./list2

% Here's the dot product of list1 and list2:
dot(list1,list2)

% and the cross product of a pair of 3-D vectors.  Notice that a x b equals
% -b x a as expected.  Also notice that the cross product produces a vector
% output (also as expected).
cross([1,2,3],[4,5,6])
cross([4,5,6],[1,2,3])

% MATLAB has a function that will generate n linearly spaced numbers
% between the limits a and b called linspace(a,b,n)/
linspace(1,954,23)

% You can also generate n logarithmically spaced numbers between 10^a and
% 10^b using logspace(a,b,n).
logspace(-2,2,12)