You are on page 1of 23

Notes sur Matlab R2013a 32 Bits Win 32 ou

64 Bits
2013-2014
Rpertoire des programmes internes:
C:\Program
Files\MATLAB\R2010a\toolbox\matlab\polyfun
Prof. Mr s.ACHAKIR
14 septembre 2014

Table des matires

1 ANALYSE
1.1 Oprations . . . . . . . . . . . . . . . . . . . . . . . .
1.2 Traage de fonctions . . . . . . . . . . . . . . . . . .
1.3 Drivation . . . . . . . . . . . . . . . . . . . . . . . .
1.4 Primitive . . . . . . . . . . . . . . . . . . . . . . . . .
1.5 Limites . . . . . . . . . . . . . . . . . . . . . . . . . .
1.6 Formule de Taylor . . . . . . . . . . . . . . . . . . . .
1.7 Division euclidienne des polynmes . . . . . . . . .
1.8 Oprations sur les polynmes . . . . . . . . . . . . .
1.9 Dcomposition en lments simples . . . . . . . . .
1.10 Rsolution exactedes quations diffrentielles . . . .
1.10.1 Equations diffrentielles du premier ordre .
1.10.2 Equations diffrentielles du second ordre . .
1.11 Rsolution numrique des quations diffrentielles
1.12 Inversion de fonction numrique . . . . . . . . . . .
1.13 Calcul dintgrales par commandes internes . . . .
1.13.1 trapz : mthode des trapzes . . . . . . . . .
1.13.2 quad : mthode de Simpson . . . . . . . . . .
1.13.3 quadgk : mthode de Gauss-Konrod . . . . .
2 ALGEBRE
2.1 Matrices . . . . . . . . . . . . . . .
2.1.1 Matrice uniligne . . . . . .
2.1.2 Matrice unicolonne . . . . .
2.1.3 Matrice carre . . . . . . . .
2.1.4 Matrice rectangulaire . . . .
2.2 Oprations sur les matrices . . . .
2.2.1 Somme . . . . . . . . . . . .
2.2.2 Multiplication scalaire . . .
2.2.3 Multiplication matricielle .
2.3 Transpose dune matrice . . . . .
2.4 Dterminant dune matrice carre .
2.5 Inverse dune matrice . . . . . . . .
2.6 Rsolution dun systme linaire .

.
.
.
.
.
.
.
.
.
.
.
.
.
2

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

4
4
4
5
6
6
6
7
7
7
8
8
9
9
10
10
10
11
11

.
.
.
.
.
.
.
.
.
.
.
.
.

12
12
12
12
12
13
13
13
13
13
14
14
14
15

TABLE DES MATIRES

TABLE DES MATIRES

3 METHODE DES MOINDRES CARRES :linear least squares


16
3.1 Polynme au sens des moindres carrs . . . . . . . . . . . . . . . . . . . . . . 16
3.2 Ecriture dun polynmeet calcul de valeurs . . . . . . . . . . . . . . . . . . . 18
4 PROGRAMMATION
19
4.1 Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.2 Construction dune surface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.2.1 Par construction dun maillage . . . . . . . . . . . . . . . . . . . . . . 19
4.2.2 Par construction dun maillage par meshgrid . . . . . . . . . . . . . . 19
4.2.3 Construction de lignes ou courbes de niveau . . . . . . . . . . . . . . 20
4.2.4 Reprsentation des fonctions . . . . . . . . . . . . . . . . . . . . . . . 20
[currentsection,sectionstyle=show,subsectionstyle=show,subsubsectionstyle=show]

Topo-GREA

Mr Achakir

Chapitre 1

ANALYSE
1.1 Oprations
Lors de la dfinition dune fonction, il est prfrable dutiliser les oprations ./, ., .
pour que la fonction sapplique un tableau vectoriel et faire des oprations termes
termes.
Espace ou caractre blanc est dsign par :
Somme de n termes dune suite
for k=1 :10
x(k)=k ; end sum(x) ans = 55
sum(x(1 :10)) ans = 55
sum(1 :2 :10) ans = 25
Exemples dinsertion de fonctions
% Par la classe handle
syms x
f = @( x )( x. 2 + 3. x + ( x + 1)./(1 + x. 2)) ;
u=1 :0.1 :2 ;
v=f(u) ;
% Par la commande inline
syms x
f = inline( x.2 + 2. x + 3 )
f = Inline function : f ( x ) = x.2 + 2. x + 3
u=-3 :0.1 :3 ; v=f(u) ;

1.2 Traage de fonctions


Matlab
La reprsentation se fait par : Commande inline
f=inline( x. exp( x )./(1 + x. 2) ) ;
la commande plot
>>xa=-1 :0.1 :1 ;
>>ya=f(xa) ;% ya(i)=f(xa(i)),i=1,2,...,n=length(xa)
>>plot(xa,ya,rs)
4

CHAPITRE 1. ANALYSE

1.3. DRIVATION

0.4
0.2
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1

0.5

0.5

Classe handle
f = @( x )( x. 2 + 3. x + ( x + 1)./(1 + x. 2)) ;
u=1 :0.1 :2 ;
v=f(u) ;
plot(u,v,rs)
Mupad
mupad
f := x 2 + 2 x + 3 plot( f ) plot( f , x = 9..3)
y

30

20

10

1.3 Drivation
Matlab
>> syms x
a >> f = 2. x. 3 ;
diff(f)
Topo-GREA

Mr Achakir

1.4. PRIMITIVE

CHAPITRE 1. ANALYSE

ans =6 x 2
b f=inline( 2. x. 3 )
diff(f(x)),diff(f(x),2)
c f = @( x )(2. x. 3) ;
diff(f(x)) ans =6 x 2
Mupad
f :=ln(x) diff(f,x) diff(diff(f,x),x)

1.4 Primitive
>>syms x c
a >> f = 3. x. 3 + x + 3 ; >> F=int(f)+c
F = c + ( x (3 x 3 + 2 x + 12))/4
b f = @( x )(2. x. 3) ;
int(f,x) ans =x 4/2
int(f(x)) ans =x 4/2

1.5 Limites
Matlab
>> syms x
a >> f = sin( x )./x ;
>> l=limit(f,x,0)
l =1
b f=@(x)(sin(x)./x) ; limit(f(x),0)
ans =1 Mupad
f := (sqrt(4 + x2 ) 2)/( x2 ) limit( f , x = 0)

1.6 Formule de Taylor


Matlab
>> %n-1 : degr du polynme de Taylor ;
>> % au voisinage de a ;
>>n=8 ;a=0 ;
>> P = taylor (1./(1 x ), n, a)
P = x7 + x6 + x5 + x4 + x3 + x2 + x + 1
Mupad
f :=log(1+x)
ln(x + 1)
taylor(f,x=3,6)
ln( x + 1) = ln(4) + ( x 3)/4 ( x 3)2 /32 + ( x 3)3 /192 ( x 3)4 /1024 + ( x
Applications du cours danalyse numrique

Notes dinitiation Matlab R2013a

CHAPITRE 1. ANALYSE
3)5 /5120 + O(( x 3)6 )
ln(1 + x ) =

x
4

( x 3)2
32

( x 3)3
192

1.7. DIVISION EUCLIDIENNE DES POLYNMES

( x 3)4
1024

( x 3)5
5120

+ o ( x 3 )5

1.7 Division euclidienne des polynmes


P = x 4 + 3 x 3 + x + 4 ,Q = 2 + 3 x + 2
v = [ 1 3 0 1 4 ] ;
u = [1 2 2]
q :quotient ; r :reste
[q, r ] = deconv(v, u)
q = 102
Q = x22
r = 00078
R = 7x+8
v=conv(q,u)+r
P = @( x )((conv(q, u) + r ) [ x 4; x 3; x 2; x; 1])

1.8 Oprations sur les polynmes


1. Somme
P = @( x )( x4 + 2 x2 + 2 x + 11)
P( x ) + Q( x )
2. Produit
expand(( x + 2)2 ( x 3) ( x + 4))
3. Factorisation
f actor ( x4 + 3 x3 + 12 x2 20 x 48)

1.9 Dcomposition en lments simples


>> syms x
>> P = 6./( x. 4 + 6. x. 3 + 11. x. 2 + 6. x + 0) ;
>> %N :coefficents du numrateur ;
>> % D :coefficients du dnominateur ;
>> % dans lordre dcroissant ;
>> N = [6] ;
>> D = [1 6 11 6 0] ;
>> [ A, B, C] = residue( N, D )
A=
-1.0000
3.0000
-3.0000
1.0000
A coefficients des numrateurs des lments simples.
Topo-GREA

Mr Achakir

1.10. RSOLUTION EXACTE


DES QUATIONS DIFFRENTIELLES
CHAPITRE 1. ANALYSE
B=
-3.0000
-2.0000
-1.0000
0
B :poles
C = []
C quotient de la division euclidienne.
3
3
1
P = x+13 + x+
2 + x +1 + x
>> F = 3./( x. 3 + x )
; >> N = [3]
; >> D = [1 0 1 0]
; >> [ A, B] = residue( N, D )
A=
-1.5000
-1.5000
3.0000
B=
0 + 1.0000i
0 - 1.0000i
0
1.5
1.5
3
F = x
i + x +i + x
syms x
% les puissances de x sont dans lordre dcroissant
%P( x ) = ( x 4 + 2 x + 1)/( x 2 3 x + 2) = b/a = ri /( x pi ) + . . . + ki x i + . . .
b=[1 0 0 2 1] ; a=[ 3 2] ; format rat [r,p,k]=residue(b,a)
r = 21 -4 p = 2 1 k = 1 3 7
expand(21 ( x 1) 4 ( x 2) + ( x2 3 x + 2) ( x2 + 3 x + 7)), ans = x 4 + 2 x + 1

1.10 Rsolution exacte


des quations diffrentielles
1.10.1 Equations diffrentielles du premier ordre
Matlab
syms x
>> y = dsolve( 3 Dy 3 y = x exp( x ) , y(0) = 1 , x )
y = exp( x ) + ( x2 exp( x ))/6
>> y = dsolve( x Dy 2 y = x , x )
y = C x2 x
Mupad
mupad
y=ode : :solve(3*y(x)-3*y(x)=x*exp(x),y(0)=1,y(x)) y = exp( x ) + ( x2 exp( x ))/6
Applications du cours danalyse numrique

Notes dinitiation Matlab R2013a

CHAPITRE 1. ANALYSE
1.11. RSOLUTION NUMRIQUE DES QUATIONS DIFFRENTIELLES

1.10.2 Equations diffrentielles du second ordre


Matlab
>> syms x
>> %y + 2y 3y = xe x ;
>> %y(0) = 1, y (0) = 0 ;
>> y = dsolve( D2y + 2 Dy 3 y = x exp( x ) , y(0) = 1, Dy(0) = 0 , x )
y = 15/(64 exp(3 x )) + (3 exp( x ))/4 + ( x2 exp( x ))/8 (exp( x ) (4 x 1))/64
>> syms x
>> %y 2y + y = x ;
>> %y(0) = 0, y (0) = 1 ;
>> y = dsolve( D2y 2 Dy + y = x , y(0) = 0, Dy(0) = 1 , x )
y = x 2 exp( x ) + 2 x exp( x ) + 2
Mupad
y = ode :: solve(y ( x ) + 2 y ( x ) 3 y( x ) = x exp( x ), y(0) = 1, y (0) = 0, y( x ))
y = (15 exp(3 x ))/64 + (3 exp( x ))/4 + ( x2 exp( x ))/8 (exp( x ) (4 x 1))/64
x
2 x
e x 4 x 1
e3 x
y = 15 64
+ 3 4e + x 8e ( 64 )

1.11 Rsolution numrique des quations diffrentielles


ODE45 :Mthode de Runge-kutta dordre 4
Soit
de Cauchy :
 le problme
y = ty2 , t [0; 10]
La solution exacte est :
y (0 )
=
1
dsolve( Dy t (y2 ) = 0, y(0) = 1 , t ) ansye = 1/(t2 /2 + 1)
La solution numrique approche est :
Dans lditeur de scripts :
function dy=equadiff1(t,y)
dy = t (y2 ) ;
end
Dans fx la fentre dexcution :
[ T, Y ] = ode45(@equadi f f 1, [0 10], 1) ;
f = @(t)(1./((t. 2)./2 + 1)) ;
Z=f(T) ;
plot(T,Y,-,T,Z,o) ;

Topo-GREA

Mr Achakir

1.12. INVERSION DE FONCTION NUMRIQUE

CHAPITRE 1. ANALYSE

0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1

10

1.12 Inversion de fonction numrique


>> syms x
>> f = x. 3 + 2 ;
>> g = f inverse( f )
Warning : finverse(x3 + 2) is not unique.
g=
( x 2)( 1/3)
>> f = log( x + 2) ;
>> g = f inverse( f )
g=
exp( x ) 2

1.13 Calcul dintgrales par commandes internes


1.13.1 trapz : mthode des trapzes
clear all
syms x
a=0 ;b=3 ;
u=a :0.01 :b ;
f = @( x )( x.2 ) ;
v=f(u) ;
trapz(u,v) ans = 9

Applications du cours danalyse numrique

10

Notes dinitiation Matlab R2013a

CHAPITRE 1. ANALYSE

1.13. CALCUL DINTGRALES PAR COMMANDES INTERNES

1.13.2 quad : mthode de Simpson


quad(f,a,b) ans = 9

1.13.3 quadgk : mthode de Gauss-Konrod


quadgk(f,a,b)

Topo-GREA

ans = 9

11

Mr Achakir

Chapitre 2

ALGEBRE
2.1 Matrices
2.1.1 Matrice uniligne
A=[-1 2 -2/3 123]
ou A=[1, 2, 2/3, 123]
A = -1.0000 2.0000 -0.6667

123.0000

2.1.2 Matrice unicolonne


A=[1; 12; 3; 5/8]
ou A=[1
12
3
5/8]
A=
-1.0000
12.0000
3.0000
0.6250

2.1.3 Matrice carre


A=[2 -1 5/3 ;2 3 11 ;-3 -4 1/2]
ou A=[2 1 5/3
2 3 11
3 4 1/2]
A=
2.0000 -1.0000 1.6667
2.0000 3.0000 11.0000
-3.0000 -4.0000 0.5000

12

CHAPITRE 2. ALGEBRE

2.2. OPRATIONS SUR LES MATRICES

2.1.4 Matrice rectangulaire


A=[2 -3 14 ;2/7 5 1/3]
A=
2.0000 -3.0000 14.0000
0.2857 5.0000 0.3333

2.2 Oprations sur les matrices


2.2.1 Somme
A=[2 5 7 ;12 13 -66] ;
B=[12 -5 10 ;10 3 60] ;
S=A+B
S=
14 0 17
22 16 -6

2.2.2 Multiplication scalaire


>> syms a
>> a A
ans =
[2 a, 5 a, 7 a]
[12 a, 13 a, 66 a]
7 A
ans =
14 35 49
84 91 -462

2.2.3 Multiplication matricielle


A=[2 11 -3 ;-2 7 -5] ;
B=[1 2 ;-3 11 ;7 9] ;
>> A B
ans =
-52 98
-58 28
Topo-GREA

13

Mr Achakir

2.3. TRANSPOSE DUNE MATRICE

CHAPITRE 2. ALGEBRE

2.3 Transpose dune matrice


A=[12 14 5 ; -2 -19 20]
A=
12 14 5
-2 -19 20
>> A
ans =
12 -2
14 -19
5 20
>> transpose( A)
ans =
12 -2
14 -19
5 20

2.4 Dterminant dune matrice carre


A=[1 0 11 3 ;-1 2 11 0 ;4 5 0 -3 ;1 2 3 5]
A=
1 0 11 3
-1 2 11 0
4 5 0 -3
1 2 3 5
>> det( A)
ans = -1152

2.5 Inverse dune matrice


>> format rat
A=[1 0 11 3 ;-1 2 11 0 ;4 5 0 -3 ;1 2 3 5]
>> inv(A)
ans =
323/1152 -37/144 79/576 -11/128
-131/576 13/72 17/288 11/64
77/1152 5/144 1/576 -5/128
-1/192 -1/24 -5/96 11/64
>> A inv( A)
ans =
1 * 0 0
0 1 * *
* 0 1 *
Applications du cours danalyse numrique

14

Notes dinitiation Matlab R2013a

CHAPITRE 2. ALGEBRE

2.6. RSOLUTION DUN SYSTME LINAIRE

* * 0 1
ou A 1

2.6 Rsolution dun systme linaire


%AX=B
A= ?,B= ?
X=linsolve(A,B) ;
X=A1 B ;
X=A \ B ;
A=[1 2 3 ;-2 4 7 ; 3 8 6]
A=
1 2 3
-2 4 7
3 8 6
>> B = [1; 2; 8]
B=
1
-2
8
>> X = linsolve( A, B)
X=
4/5
13/10
-4/5
>> X = A 1 B
ou >> X = A\ B
X=
4/5
13/10
-4/5

Topo-GREA

15

Mr Achakir

Chapitre 3

MTHODE DES MOINDRES CARRES :


linear least squares
3.1 Polynme au sens des moindres carrs
Donnes
x0 , x1 , x2 , . . . , x n 1 , x n ,
y0 , y1 , y2 , . . . , y n 1 , y n ,
Polynme des moindres carrs de degr m
m

ak x k

P( x ) =

k=0


a0
y0
a1
y1


,Y= y2 ,
a
On pose y(k) = P( xk ), k = 0, 1, 2, . . . , n,A=
2


. . .
. . .
am
yn

2
3
m
1 x0 x0 x0 . . . x0
1 x1 x 2 x 3 . . . x m
1
1
1

2 x3 . . . x m .
et t G=
1
x
x
2
2
2
2

. . . . . . . . . . . . . . . . . .
1 xn x2n x3n . . . xnm
On cherche les coefficients ak
, tels que :
n

(yk y(k))2 = kY t ( A G)k2


k=0

soit minimale.

G G A =t G Y

Si t G G est inversible alors


A=

GG

 1 t

GY

polyfit :donne les coefficients du polynme des moindres carrs dans le sens dcroissant.
polyval :calcule la valeur de ce polynme en tout point x.
Am=polyfit(x,y,m)%m degr du polynme des moindres carrs.
16

CHAPITRE 3. MTHODE DES MOINDRES CARRES :


LINEAR LEAST SQUARES
3.1. POLYNME AU SENS DES MOINDRES CARRS
valeury=polyval(Am,valeurx
>> x = [2 1.5 1 0 1 1.5 2]
>> y = [3.5 2 1.5 0 1.3 2.5 3.9]
y = 7/2 2 3/2 0 13/10 5/2 39/10
x = -2 -3/2 -1 0 1 3/2 2
>> A4 = poly f it( x, y, 4)
A4 = -122/1871 224/7155 1949/1708 -31/14310 679/4609
>> y1 = polyval ( poly f it( x, y, 4), 2.7)
y1 = 2957/527
>> y1 = polyval ( A4, 2.7)
y1 = 2957/527
>> xx = 3 : 0.1 : 3 ;
>> yy = polyval ( A4, xx ) ;
>> plot( xx, yy)

0
3

Approximation dune fonction par le polynme des moindres carrs


f = @( x )(1./(1 + x.2 )) ;
xa=-1 :1 :5
xa = -1 0 1 2 3 4 5
ya=f(xa)
A4=polyfit(xa,ya,4)
A4 = -0.015138 0.14554 -0.36392 -0.10834 0.93266
Donnes pour la reprsentation graphique
xx=-1 :0.1 :5 ;
yf=f(xx) ;
yp=polyval(A4,xx) ;
plot(xx,yf,r,xx,yp,b)

Topo-GREA

17

Mr Achakir

3.2. ECRITURE DUN POLYNME


ET CALCUL DE VALEURS

CHAPITRE 3. MTHODE DES MOINDRES CARRES :


LINEAR LEAST SQUARES

1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
1

3.2 Ecriture dun polynme


et calcul de valeurs
>> syms x
>> t = [1; x; x 2; x 3; x 4] ;
>> a = [1 2 3 5 11] ;
>> P = a t ;
>> P
P=
11 x4 5 x3 + 3 x2 2 x + 1
>> Q = inline( 11 x 4 5 x 3 + 3 x 2 2 x + 1 )
Q=
Inline function :
Q( x ) = 11 x4 5 x3 + 3 x2 2 x + 1
>> Q(0) ans = 1
>> Q(3) ans = 1060

Applications du cours danalyse numrique

18

Notes dinitiation Matlab R2013a

Chapitre 4

PROGRAMMATION
4.1 Function
Dans lediteur de scripts :
function [y]=fonction(x)
y = 1 + 2. x + x. 2
; return
appele depuis la fentre dexcution par son nom :fonction
fonction(5)
ans = 36
>> x = 2 : 0.1 : 2 ;
>> y = f onction( x ) ;
>> plot( x, y)

4.2 Construction dune surface


4.2.1 Par construction dun maillage
z=f(x,y)
x=-1 :0.1 :1 ;
>>y=-1 :0.1 :1
; >>for i=1 :length(x)
for j=1 :length(y)
z(i, j) = sqrt(2 x (i ) 2 y( j) 2) ;
end
end
>> mesh(x,y,z)

4.2.2 Par construction dun maillage par meshgrid


1. f = @( x, y)(2 x. 2 y. 2) ;
>> f
f=
19

4.2. CONSTRUCTION DUNE SURFACE

CHAPITRE 4. PROGRAMMATION

@( x, y)(2 x.2 y.2 )


>> x=-1 :0.1 :1 ;
>> y=x ;
>> [x1,y1]=meshgrid(x,y) ;
z=f(x1,y1) ;
>>mesh(x1,y1,z)
2. clear all
[x,y]=meshgrid(-2 :0.1 :2,0 :0.1 :3) ;
z = x. exp( x. 2 y. 2) ;
mesh(x,y,z)
surface(x,y,z)
surf(x,y,z)% utiliser le bouton rotate pour afficher la surface en 3D.

4.2.3 Construction de lignes ou courbes de niveau


clear all
[x,y]=meshgrid(-2 :0.1 :2,0 :0.1 :3) ;
z=x. exp( x. 2 y. 2) ;
% Construction de 5 lignes de niveau
contour(x,y,z,5)
% Construction de 15 lignes de niveau
contour(x,y,z,15)
contourf(x,y,z,10)

4.2.4 Reprsentation des fonctions


Fonctions implicites
1. Cercle
fonction1=@( x, y)( x. 2 + y. 2 4) ;
%x2 + y2 = 22 : C(O,r=2)
ezplot(fonction1) % Coloriage de lintrieur dun cercle :
hold on
c=ezplot(fonction1) ;
set(c,color,b) ;
2. Ellipse ellipse=@( x, y)(( x. 2)./4 + (y. 2)./25 1) ;
ezplot(ellipse)
3. Hyperbole hyperbole=@( x, y)(( x. 2)./4 (y. 2)./25 1) ;
ezplot(hyperbole)
4. f(x,y)=0 f=@( x, y)( x.2 3. y.3 + x + y 3) ; ezplot(f)
f = x2 3y3 + x + y 3
Applications du cours danalyse numrique

20

Notes dinitiation Matlab R2013a

CHAPITRE 4. PROGRAMMATION

4.2. CONSTRUCTION DUNE SURFACE

Fonctions et asymptotes
1. Asymptotes verticale et horizontale % f ( x ) = (3x2 + 6x 1)/( x2 + x 3)
syms x
num = 3 x 2 + 6 x 1 ;
denom = x 2 + x 3 ;
f=num/denom ;
roots=solve(denom) ;
roots
roots =
131/2 /2 1/2
131/2 /2 1/2
% Asymptotes verticales : x=-(1+sqrt(13))/2,x=(-1+sqrt(13))/2
limit(f,inf)
ans =3
% y=3, asymptote horizontale
% On peut reprsenter les asymptotes par les commandes :
%ezplot(fun,[xmin,xmax]) plots fun(x) over the domain : xmin < x < xmax.
ezplot(f)% reprsentation de Cf
hold on % garde Cf dans la figure
% Plot horizontal asymptote y=3
plot([-6 6],[3 3],y)% y couleur yellow, g couleur green
%plot vertical asymptotes x = x1 , x = x2
plot(double(roots(1))*[1 1],[-5 10],r)% couleur red
plot(double(roots(2))*[1 1],[-5 10],r)
title(f(x)=(3x2 + 6x 1)/( x2 + x 3),Asymptotes verticale et horizontale)
hold off
f(x)=(3x2+6x1)/(x2+x3),Asymptotes verticale et horizontale

4
6

0
x

Reprsentation graphique
2. Asymptotes obliques % f(x)=x+2+e(-x)/(x-2)
Topo-GREA

21

Mr Achakir

4.2. CONSTRUCTION DUNE SURFACE

CHAPITRE 4. PROGRAMMATION

% x=2 asymptote verticale, y=x+2 asymptote oblique


syms x
f=x+2+exp(-x)/(x-2) ;
yob=x+2 ;
hold on
ezplot(f)
ezplot(yob,[-10 10])
plot(2*[1 1],[-4 4],g)
f(x)=x+2+(ex)/(x2),Asymptotes verticale et horizontale
12
10
8
6
4
2
0
2
4
6
8
10

0
x

10

Reprsentation graphique
Suites et formes itratives et test darrt
1. Boucle for ...
clear all
syms x
x0=0.5 ;
F=@(x)(log(1+x)+0.2) ;
u(1)=x0 ;
for k=1 :10
u(k+1)=F(u(k)) ;
end
2. Condition if ...
if condition
instruction ;
else
instruction ;
end
3. Tant que while ...
x=F(x) et x0 donn, xn+1 = F( xn ) n=0,1,2,3....
Applications du cours danalyse numrique

22

Notes dinitiation Matlab R2013a

CHAPITRE 4. PROGRAMMATION

4.2. CONSTRUCTION DUNE SURFACE

function[u]=phi(x0,F,testarret )
u(1)=x0 ;
k=1 ;
u(k+1)=F(u(k)) ;
while(abs(u(k+1)-u(k))>testarret )
k=k+1 ;
u(k+1)=F(u(k)) ;
end
end
phi est appele depuis la fentre dexcution par :
clear all
syms x
testa rret = 10( 4) ;
x0=0.5 ;
F=@(x)(log(1+x)+0.2) ;
xx=0 :0.1 :2 ;
yy=F(xx) ;
plot(xx,xx,xx,yy)

FIN

Topo-GREA

23

Mr Achakir

You might also like