clear

// Exo 1 : 

A = diag(1:7)
B = zeros(4,9) ; B(1,:)=1
C = [ 2*ones(3,1) , [1:3]' , -1*ones(3,3) ]
D = [ 2*ones(5,3) , diag(ones(5,1)) ; diag(1:3) , zeros(3,5) ]
E = ones(6,6); E(5,3) = 0

disp("A",A)
disp("B",B)
disp("C",C)
disp("D",D)
disp("E",E)

// Exo 2 : 

A = int(5*rand(5,5))
B = inv(A)*A - eye(5,5)
normB = norm(B)

disp("A",A)
disp("A A-1-I",B)
disp("norm 2 de AA-1-I",normB)

// Exo 3 : 

A = int(5*rand(5,3))
B = [5*ones(5,1), 2*ones(5,1), 7*ones(5,1)]
D= A.*B

disp("A",A)
disp("A.*B",D)

C = diag([5,2,7])
E = A*C
disp("A*C",E)

// Exo 4 : 

A = rand(4,4)
A = A + A' // on symetrise pour etre diagonalisable sur R
disp("A",A)
[D,P] = bdiag(A)
disp("diag",D)
disp("P",P)

A = rand(4,4)
[D,v] = bdiag(A+%i*0)
disp("diag",D)
disp("P",P)

// Exo 6 : 

function f=Heaviside(x)
    
    if x >= 0 then
        f=1
    else 
        f=0
    end
    
endfunction

n=100
for i=1:n 
    X(i) = (i-n/2)*10/n 
    Y(i) = Heaviside(X(i))
end

scf(1)
plot(X,Y,'-xb')


