function [a b] = examp(x,y)

global a % gobal variables must be declared everywhere

a = zeros(6,6) ; % 3x3 zeros matrix
b = eye(6,6) ; % 3x3 identity matrix

c = a*b ; % matrix mult.
d = a.*b ; % pointwise

c = c + rand(6,6) ; % rand is uniform [0,1]
d = c .* randn(6,6) ; % randn is normally dist. zero mean, var=1

v = ones(6,1) ; % a column vector of ones 
w = ones(1,6) ; % a row vector of ones 

a = w * v ; % dot product

for i=1:6 % could be 1:2:6 which would step by 2
    for j=1:6
        a(i,j) = i ;
    end
    
    if(i == j)
        b(i,j) = 0 ;
    end
end

sum(a) % sum the columns
sum(a,2) % sum the rows
sum(sum(a)) % summing everyhting
max(a) % same goes for max (and min)
max(max(a))

v = (1:6) ; % defines a 1x6 vector

v>3 % generates a vector indicating where the condition is met

w(v>3) % get the components of w where the cond. on v are met

v(1:end/2) % half the vector

v(1:2:end) % odd components of the vector

v = reshape(v,2,3) % change size from a vector to a matrix

size(v) % the size of v

w = diag(w) % vec - > diagonal mat
w = diag(w) % dianoal of a mat -> vec

w' % transpose

v = rand(32,1) ; 
v = sort(v) ; % sorting the vector

figure(1)
clf
plot(v,'.-g')
hold on          % so that we can plot more on the same figure
plot(v.^2,'xr')

figure(2)
clf
for i=1:4
    subplot(2,2,i) % 2x2 subplots within the same figure
    plot(v.^i)
end

a = a + a' ; % a plus its transpose is symmetric

M = a.^2 + eye(size(a)) ; % defining a new matrix (note .^ is point wise power, as apposed to a^2=a*a)

b = inv(M) * w % solving Mb = w by computing the inv. of M

y = M * b - w ; % the error vector

norm(y) % and its norm



function g = func(h)

global a % gobal variables must be declared everywhere

g = a ;