// Exercise 1
// ----------

// 1)
v1 = 1:.1:3

// 2)
v2 = 3:-.1:1

// 3)
v3 = (1:10)^2

// 4)
n = (1:10);
un = ones(1,10);
v4 = (- un).^n .* (n^2)

// 5)
un = ones(1,10)
v5 = [0*un, un]

// Exercise 2
// ----------

// 1)
m = matrix(1:36,6,6)'
m = [1:6;7:12;13:18;19:24;25:30;31:36]

// 2)
n = 5
C = zeros(n,n);
for i = 1:n
   C(i,i) =2;
end;
for i = 1:n-1
   C(i,i+1) = -1;
end;
for i = 2:n
   C(i,i-1) = -1;
end;

// ou

C = 2*eye(n,n)-diag(ones(n-1,1),1)-diag(ones(n-1,1),-1)


// Exercise 3
// ----------

X = 0:.1:4*%pi;
Y = sin(X) + X;
plot2d(X,Y)
xtitle('Exemple','x','sin(x) + x');


// Exercise 4
// ----------

function C = alterne2_colonne(A,B)

[n,m] = size(A)

C = []

for i=1:m
  C = [C, A(:,i), B(:,i)];
end;

endfunction

// Exercise 5
// ----------
clear
n = 50;
F = ones(n,1);
A = eye(n,n);

x = matrix(linspace(0,1,n),n,1);
Dx = 1/(n-1);
u_exact = 1- (exp(x) + exp(1-x))/(1+exp(1));


 F(1) = 0;
 F(n) = 0;

for i=2:n-1
   A(i,i) = A(i,i) + 2./Dx^2;
   A(i,i-1) = -1/Dx^2;
   A(i,i+1) = -1/Dx^2;
end;


u_c = A\F;
erreur = norm(u_exact-u_c)

xbasc()
plot2d(x,u_c,style=[-1])

x=linspace(0,1,100);
u_exact = 1- (exp(x) + exp(1-x))/(1+exp(1));
plot2d(x,u_exact,style=[1])

xtitle('Solution','x','u(x)');



