Une année de MAPLE et SCILAB en MP* (french)
S O M M A I R E
1 X 2012
2 Scilab for dummies
2.1 Avant de commencer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Scilab comme super-calculatrice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2.1
Les opérations de base . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2.2
Un brin d’informatique . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2.3
Définir une fonction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3 L’objet de base de Scilab : la matrice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3.1
Utilisation d’une matrice ligne . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4 Les graphiques
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5 La programmation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5.1
Les tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5.2
Boucles for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5.3
Boucles while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5.4
Récursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 Interpolations
3.1 Schéma de Horner-Ruffini-Holdred-Newton-Al-Tusi-Liu-Hui… . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.1.1
Un peu d’histoire… . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.1.2
Complexité
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.1.3
Dérivées successives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 Interpolation de Lagrange . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3 Interpolation de Newton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3.1
L’idée . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3.2
Un exemple avec un pas constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3.3
Cas général
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.4 Observation graphique . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.5 Quelques idées pour la frise… . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4 Dérivation et intégration numérique
4.1 Dérivation numérique . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.2 Intégration numérique . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.2.1
Méthode de quadrature simplifiée déterministe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.2.2
Méthodes de NEWTON-COTES
composées . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.2.3
La méthode de ROMBERG
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.2.4
Méthode de Monte-Carlo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.3 Lectures
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5 Discrétisation d’équations différentielles
5.1 Principe
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.2 Méthode d’Euler explicite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.3 Méthode d’Euler modifiée . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.4 Méthode RK4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.5 La boîte de Pandore des approximations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.5.1
Problème mal posé mathématiquement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.5.2
Problème mal posé numériquement
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.5.3
Problème mal conditionné . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.5.4
Problèmes raides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.6 Systèmes différentiels et ordre 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.6.1
Systèmes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.6.2
Ordre 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6 Dessine-moi une matrice…
6.1 Lena . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.2 La SVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.2.1
Le théorème . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.2.2
Interprétation géométrique . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.2.3
Un exemple simple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.2.4
Approximation de rang minimum d’une matrice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.3 Manipulation d’images
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.3.1
Scilab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
43
6.3.2
Manipulations basiques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.3.3
Gagner de la place . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.3.4
Enlever le bruit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.3.5
Détection de bords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.4 MAPLE et les matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7 Systèmes dynamiques
7.1 Logistique . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Correction des exercices
http://informathix.tuxfamily.org/?q=node/58
funcprot(0); l = read('~/lena.csv',512,512); lena = l'; x = [1:512]; y = [512:-1:1]; xset('colormap',graycolormap(256)); isoview(0,512,0,512); //grayplot(x,y,lena) function M = retourne(m) n = length(m(1,:)); M = zeros(n,n); for i = 1:n for j = 1:n M(i,j) = m(i,n + 1 - j) end end endfunction function M = miroir(m) n = length(m(1,:)); M = zeros(n,n); for i = 1:n for j = 1:n M(i,j) = m(n + 1 - i,j) end end endfunction //grayplot(x,y,retourne(lena)) //grayplot(x,y,miroir(lena)) //grayplot(x,y,255-lena) function C = comp_svd(m,k) [U,S,V] = svd(m); V = V' n = length(m(1,:)); C = zeros(k,k); for p = 1:k C = C + S(p,p)*(U(1:k,p) * V(k,1:k)) end C = floor(C) endfunction //plot(x,diag(S)/S(1,1)) //grayplot(x,y,comp_svd(lena,50)) function R = resolution(m,k) n = floor(length(m(1,:))/k); R = zeros(n,n); for i = 1:n for j = 1:n R(i,j) = m(k*i,k*j) end end endfunction //clf(); //isoview(0,256,0,256); grayplot((1:512/2),(512/2:-1:1),resolution(lena,2)) function Q = quantification(m,k) Q = floor(m ./ k) endfunction //grayplot(x,y,quantification(lena,64)) //grayplot(x,y,quantification(lena,64)) function C = contraste(m,f) C = f(m) endfunction deff('[f] = f(x)', 'f = x .* x'); //deff('[f] = f(x)', 'f = floor(sqrt(x))'); //deff('[f] = f(x)', 'f = 255 - x'); //xset('colormap',graycolormap(512^2)); //grayplot(x,y,contraste(lena,sqrt)) //xset('colormap',graycolormap(512)); function F = fcontour(i,j,m) F = floor(sqrt((m(i,j-1)-m(i,j+1))^2 + (m(i-1,j)-m(i+1,j))^2)) endfunction function C = contour(m) n = length(m(1,:)); C = zeros(n,n); for i = 2:n-1 for j = 2:n-1 C(i,j) = 255 - fcontour(i,j,m) end end endfunction //grayplot(x,y,contour(lena)) function M = fmed(i,j,m,k) M = floor(median(m(i-k:i+k,j-k:j+k))) endfunction function C = mediane(m,k) n = length(m(1,:)); C = zeros(n,n); for i = 1+k:n-k for j = 1+k:n-k C(i,j) = fmed(i,j,m,k) end end endfunction //grayplot(x,y,mediane(lena,3)) function M = fmean(i,j,m,k) M = floor(mean(m(i-k:i+k,j-k:j+k))) endfunction function C = moyenne(m,k) n = length(m(1,:)); C = zeros(n,n); for i = 1+k:n-k for j = 1+k:n-k C(i,j) = fmean(i,j,m,k) end end endfunction //grayplot(x,y,moyenne(lena,3)) function B = bruit(m,ratio) n = length(m(1,:)); B = m + 75*grand(n,n,'bin',1,ratio/100) endfunction //grayplot(x,y,bruit(lena,20)) //grayplot(x,y,moyenne(bruit(lena,20),2))