% history090308.m
% K. Ming Leung, September 25, 2008.

clear;
% can be used as a calculator:
2+6
% MATLAB language uses the free format in all its statements.
% This means that spaces and blanks lines do not matter.
% The above can be typed as
2 + 6

% Has built-in variables like pi:
pi
% Output normally displayed with only 4 decimal places.
% Numbers are stored as double precision floating-point numbers
% with about 15 decimal places of precision.
% Use format long to display more decimal places.
% Can find out more about formatting display outputs using format:
help format

% store data in variables:
radius = 0.352
% the data can then be used in a calculation later:
area = pi*radius*radius
% MATLAB is an interpretive language.
% Data stored in variables are retained until the session closes,
% or until a variable is cleared by the user.
radius  % data stored can be retrieved

% use whos to see what variables are currently in the memory
% the data type, the amount of memory used, and the array sizes
% are also displayed together with a list of name currently in memory.
whos

% use the clear function to clear a variable from memory
clear radius
% use whos to see that the variable has been cleared:
whos
% clearing more than 1 variable:
clear area volume
whos

% MATLAB uses IEEE floating-point system and infinity can be handled:
% The predefined symbol for infinity is Inf:
a = 2/0
% Reasonable calculations involving infinity can be handled:
a * 8
a - 20000000
Inf - a

% The most common data type in MATLAB is the double precision
% floating-point numbers (includes every number we have encountere so far).

% Another data type in MATLAB is strings.
% A string is a sequence (array) of characters 
% (letters, digits, punctuation marks.)
b = 'Hello world!'

8 * b 
% In the above calculation, each character in the string is first converted
% into numbers given by the ASCII value of the character, before the
% calculation is carried out.

% MATLAB automatically uses complex numbers in calculations:
c1 = sqrt(-9)           % the square root of a negative number
complexAngle = asin(2)  % the arcsin of 2 is a complex angle

% simple 2D plots:
x=0:0.1:1; y=x.^2; plot(x,y)        % plotting a curve
x=0:0.1:1; y=x.^2; plot(x,y,'o')    % plotting only data points
x=0:0.1:1; y=x.^2; plot(x,y,x,y,'o')    % both curve & points
x=0:0.1:1; y=x.^2; plot(x,y,x,y,'ro')   % pts in red circles
x=0:0.1:1; y=x.^2; plot(x,y,x,y,'rx')   % pts in red crosses
x=0:0.1:1; y=x.^2; plot(x,y,'k',x,y,'bx')   % curve in black, pts in blue crosses

