% LIST of MATLAB commands and constructs
%-----------------------
a = [1 2 3] % row vector
c = [1;2;3] % column vector
a*c         % row*column = number (inner product)
dot(a,c)    % ditto
A=c*a       % column*row = matrix
a*a         % error
b=a.^2      % componentwise power
a.*b        % componentwise product (a^3)
exp(a)      %   "  exponential
log(ans)    % inverse
sqrt(a)    
format long % 16 digits
sqrt(a)
format      % restore default (short) format
2^(-24)
sum(b)      % sum of components
mean(b)     % mean of components
pi
y=tan(pi/6)
%-----------------------------
% arrays
B=[-3 0 1;2 5 -7;-1 4 8]
x=B\c       % solve B*x=c
norm(B*x-c)
e=eig(B)
[V,D]=eig(B)% V eigenvectors D eigenvalues
v=1:6
w=2:3:10
y=1:-0.25:0
C=[A,[8;9;10]]
D = [B;a]
C(2,3)
C(2:3,1:2)
I3 = eye(3,3)
Y = zeros(3,5)
Z=ones(2)
%-----------------------------
rand('state',20)  [0,1] uniform
randn('state',20) % for repeatable random nambers, set state of RNG (0,1)normal
who
whos
% --------------------
% continued fraction
g=2;
for k=1:10,
  g= 1+1/g;
end
g
%----------------------------
t=0:0.005:1
z=exp(10*t.*(t-1)).*sin(12*pi*t)
plot(t,z)
%----------------------------
hist(randn(1000,1)) (normal(0,1); 1000 points)
%-----------------------
%  growth of random Fibonacci sequence (x_n+1 = x_n +/- x_n-1)
% script rfib
clear
rand('state',100)
m=300  % no. of iterations
x=[1 2]; % IC
for n = 2:m-1, x(n+1) = x(n)+sign(rand-0.5)*x(n-1);
end
semilogy(1:1000,abs(x))
c=1.13198824; %asymptotic constant (Viswanath's constant)
hold on
 semilogy(1:1000,c.^[1:1000])
hold off
--------------------------
%SWEEP Generates a volume-swept 3D object
N=10; %no. of increments (vary!)
z=linspace(-5,5,N)';
radius = sqrt(1+z.^2); %change sqrt to other functions
theta = 2*pi*linspace(0,1,N);
X=radius*cos(theta);
Y=radius*sin(theta)
Z=z(:,ones(1,N));

surf(X,Y,Z)
axis equal
%-----------------------------------------------------------------------
% Script: cells
NYC_Lat  = struct('d',40,'m',45,'s',27);
NYC_Long = struct('d',75,'m',12,'s',32);
C1       = struct('name','New York','lat',NYC_Lat,'long',NYC_Long);
C1.name
C1.long.m
C=cell(2,2);
C{1,1}=[1 2;3 4];
C{1,2}=[5;6];
C{2,1}=[7 8];
C{2,2}=9;
M=[C{1,1} C{1,2};C{2,1} C{2,2}] 
%-----------------------------------------------------------------------
