%LECTURE 1
%(Selcuk Bayin, METU-NCC, bayin@metu.edu.tr)
%BASIC MATHLAB COMMANDS
%Creating matrices
clc %Clears the command window
ARow=[1 2 3] %Creates a row matrix
%%
AColumn=[1;2;3] %Creates a column matrix
%%
A=[1 2 3;3 1 2;1 3 1] %Creates a 3x3 matrix: A
%%
B=[1 1 2;1 2 1;2 1 1] %Creates a 3x3 matrix: B
%%
%Operations with matrices
AB=A*B %Product
%%
AplusB=A+B %Addition
%%
tranposeA=A' %transpose
%%
A
%%
5*A
%%
%Special Matrices
E=eye(3) %Creates 3x3 Identity matrix 
%%
zeros(3) %Creates 3x3 matrix of zeros
%%
%Uniform distribution
F=rand(3) %Creates a random matrix with uniform distribution
%%
%Normal distribution
G=randn(3) % Creates a random matrix with normal distribution
%%
%Creating matrices of size mxn with all zeros or all ones
G1=ones(3,2) 
%%
G2=zeros(2,5)
%%
G3=ones(size(A))
%%
G4=zeros(size(A))
%%
G5=eye(size(A))%Identity matrix of size A
%%
AA=rand(5)
%%
AAA=AA'
%%
v=[1 2 3]
w=[1 2 1]
diag(v) %diagonal matrix with its diagonal terms as vector v
%%
T=[1 1 1;2 2 2;3 3 3]
%%
%Changing an element
T1(1,2)=99 %Changes the element 12 to 99
%%
T1(2,3)=33,
T1(3,3)=55
%%
%Changing an entire row or a column
T
%%
T(1,:)=44 
%%
T(:,3)=66
%%
%Interchanging rows
T1=[1 2 3;2 1 3;1 4 5]
%%
T1([1 2],:)=T1([2 1],:) %Interchanges first and the second rows 
%%
A=rand(4)
A(1,2)
%%
A(2,2)=2
%%
%Submatrices
A
%%
A(2,:) % Writes the second row
A(:,3) % writes the third column
%%
A
A([2:4],3:4)
%%
A([2,4],:) 
%%
A(:)
%%
v=[1 2 3 4 5 6 7 8 9]
%%
v(4)
%%
v(1:5)
%%
v(6:end)
%%
v(1:2:8) 
%%
%Triangular matrices from A
A
triu(A)
tril(A)
%%
%Scalars associated with matrices
A=[1 2 1;2 3 1;1 1 1]
det(A)
%%
A
Arank=rank(A),
%%
A
Asize=size(A)
%%
A
Atrace=trace(A),
%Elementary matrices:
%They are obtained by a single elementary 
%row operation on the identity matrix
%%
clc
E=eye(3)
%%
E(2,3)=-2 %(-2)*Row3+Row2
%%
A=[1 2 3;3 2 1;2 1 3]
%%
EonA=E*A %Action of E on A: (-2)*Row3+Row2
%%
A
%%
%Multiply Row1 by 2
E1=[2 0 0;0 1 0;0 0 1]
%%
E1onA=E1*A
%%
A
%%
E2=[1 0 0;0 3 0;0 0 1]
%%
E2onA=E2*A
%%
E2onE1=E2*E1
%%
E2onE1onA=E2onE1*A
%%
%LU FACTORIZATION
A=[1 2 1;1 2 6;4 5 3]
%%
[L,U,P]=lu(A)
%%
P*A
L*U
%%
%EXAMPLE FROM THE BOOK
A=[3 5 2;0 8 2;6 2 8]
%%
[L,U,P]=lu(A)
%%
PA=P*A
LU=L*U
%%
%Kreyszig's factorization
LL=[1 0 0;0 1 0;2 -1 1]
%%
UU=[3 5 2;0 8 2;0 0 6]
%%
LL*UU




