Vous êtes sur la page 1sur 18

République Algérienne Démocratique et Populaire

Ministère de l’Enseignement Supérieur et de


La Recherche Scientifique
UNIVERSITE MOHAMMED KHIDER DE BISKRA
FACULTE DES SCIENCES ET DES SCIENCES DE
L’INGENIEUR
DEPARTEMENT D’HYDRAULIQUE

Compte rendu de TP1 Matlab

Par :
MAAMERIA Meriem Feriel

Année Universitaire 2022/2023


Introduction:
Matlab, est un logiciel qui a été conçu pour fournir un environnement de calcul
numérique de haut niveau. Il est particulièrement performant pour le calcul matriciel
car sa structure de données interne est basée sur les matrices. Il dispose également de
grandes capacités graphiques pour, par exemple, la visualisation d’objets
mathématiques complexes. Son fonctionnement repose sur un langage de
programmation interprété qui permet un développement très rapide. Pour des
applications nécessitant un temps de calcul plus élevé, un langage compilé comme le
C++ ou le fortran, est mieux adapté.

Ce TP1 nous permet de connaitre les bases de manipulation des données de ce


logiciel, ainsi des méthodes de solutions des différentes opérations sur les matrices,
des fonctions, des systèmes d’équations linéaires.

Application 1 :
-8:0.25:-5

ans =

Columns 1 through 12

-8.0000 -7.7500 -7.5000 -7.2500 -7.0000 -6.7500 -6.5000 -6.2500 -6.0000


-5.7500 -5.5000 -5.2500

Column 13

-5.0000

>> 3:0.1:15

ans =

Columns 1 through 12

3.0000 3.1000 3.2000 3.3000 3.4000 3.5000 3.6000 3.7000 3.8000


3.9000 4.0000 4.1000

Columns 13 through 24

4.2000 4.3000 4.4000 4.5000 4.6000 4.7000 4.8000 4.9000 5.0000


5.1000 5.2000 5.3000

Columns 25 through 36

5.4000 5.5000 5.6000 5.7000 5.8000 5.9000 6.0000 6.1000 6.2000


6.3000 6.4000 6.5000
Columns 37 through 48

6.6000 6.7000 6.8000 6.9000 7.0000 7.1000 7.2000 7.3000 7.4000


7.5000 7.6000 7.7000

Columns 49 through 60

7.8000 7.9000 8.0000 8.1000 8.2000 8.3000 8.4000 8.5000 8.6000


8.7000 8.8000 8.9000

Columns 61 through 72

9.0000 9.1000 9.2000 9.3000 9.4000 9.5000 9.6000 9.7000 9.8000


9.9000 10.0000 10.1000

Columns 73 through 84

10.2000 10.3000 10.4000 10.5000 10.6000 10.7000 10.8000 10.9000


11.0000 11.1000 11.2000 11.3000

Columns 85 through 96

11.4000 11.5000 11.6000 11.7000 11.8000 11.9000 12.0000 12.1000


12.2000 12.3000 12.4000 12.5000

Columns 97 through 108

12.6000 12.7000 12.8000 12.9000 13.0000 13.1000 13.2000 13.3000


13.4000 13.5000 13.6000 13.7000

Columns 109 through 120

13.8000 13.9000 14.0000 14.1000 14.2000 14.3000 14.4000 14.5000


14.6000 14.7000 14.8000 14.9000

Column 121

15.0000

>> -pi:100:pi

ans =

-3.1416

Application 2:
A=[1 2 3;2 3 1;3 1 2]

A=

1 2 3
2 3 1

3 1 2

>> A([2 3],:)

ans =

2 3 1

3 1 2

>> A([2 3],[1 3])

ans =

2 1

3 2

>> A([2 3],1:2)

ans =

2 3

3 1

>> A(:)

ans =

>> A(5)

ans =
3

>> C=[A,zeros(3,2);zeros(2,3),eye(2)]

C=

1 2 3 0 0

2 3 1 0 0

3 1 2 0 0

0 0 0 1 0

0 0 0 0 1

Application 3 :
ones(6,4)

ans =

1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1

>> magic(5)

ans =

17 24 1 8 15

23 5 7 14 16

4 6 13 20 22

10 12 19 21 3

11 18 25 2 9

>> rand(4,2)
ans =

0.8147 0.6324

0.9058 0.0975

0.1270 0.2785

0.9134 0.5469

>> eye(15)

ans =

1 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 1 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 1 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 1 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 1 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 1 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 1 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 1 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 1 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 1 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 1 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 1 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 1 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 1 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

>> x=linspace(1,30,50)

x=

Columns 1 through 12

1.0000 1.5918 2.1837 2.7755 3.3673 3.9592 4.5510 5.1429 5.7347


6.3265 6.9184 7.5102
Columns 13 through 24

8.1020 8.6939 9.2857 9.8776 10.4694 11.0612 11.6531 12.2449


12.8367 13.4286 14.0204 14.6122

Columns 25 through 36

15.2041 15.7959 16.3878 16.9796 17.5714 18.1633 18.7551 19.3469


19.9388 20.5306 21.1224 21.7143

Columns 37 through 48

22.3061 22.8980 23.4898 24.0816 24.6735 25.2653 25.8571 26.4490


27.0408 27.6327 28.2245 28.8163

Columns 49 through 50

29.4082 30.0000

>> length(x)

ans =

50

>> A=[6 8 8 15;12 10 6 12;18 16 8 14;4 3 7 9]

A=

6 8 8 15

12 10 6 12

18 16 8 14

4 3 7 9

>> A(3,3)

ans =

>> A(1,:)

ans =

6 8 8 15

>> A(:,2)

ans =
8

10

16

>> A(1:2,3:4)

ans =

8 15

6 12

>> A([1,3],[2,4])

ans =

8 15

16 14

>> A(2,:)=[]

A=

6 8 8 15

18 16 8 14

4 3 7 9

>> size(A)

ans =

3 4

Application 5 :
>> A=[1 3 4 6;2 1 3 4;-3 2 1 3;8 -3 2 1]

A=

1 3 4 6

2 1 3 4

-3 2 1 3

8 -3 2 1
>> A'

ans =

1 2 -3 8

3 1 2 -3

4 3 1 2

6 4 3 1

Did you mean:

>> det(A-2.i)

ans =

-13.0000 -10.0000i

>> reshape(A(:),size(A))

ans =

1 3 4 6

2 1 3 4

-3 2 1 3

8 -3 2 1

>> A(3,4)

ans =

>> A(2,:)

ans =

2 1 3 4

>> A(:,3)

ans =

1
2

>> A(2:3,2:3)

ans =

1 3

2 1

>> A([1,2],[2,3])

ans =

3 4

1 3

>> A(3,:)=[]

A=

1 3 4 6

2 1 3 4

8 -3 2 1

Application 7 :
x=-3:0.1:3;
f=sin(x)+sqrt(x.^2+1);
plot(x,f)
g=cos(x)+2*x/x.^2+1;
hold on
plot(x,g,'y')

Figure I
Application 8 :
fplot('exp(-x/25)',[0,10]);

Figure II
fplot('cos(x/10)',[0,10]);

Figure III

x=0:0.1:10;
f=exp(-x/25);
g=cos(x/10);
plot(x,f,x,g)

Figure IV

Application 9 :
x1=[0:0.01:2];
f1=10*ones(size(x1));
x2=[2.01:0.01:4.99];
f2=zeros(size(x2));
x3=[5:0.01:7];
f3=-3*ones(size(x3));
f=[f1,f2,f3];
x=[x1,x2,x3];
plot(x,f),xlabel('x'),ylabel('y')
Figure V

Application 10 :
x=-2:0.1:2;
f1=1+x.^2/sqrt(x.^3+3);
plot(x,f1)
f2=x.^2;
hold on
plot(x,f2,'r')
Figure VI

Application 11 :
f=inline('sin(x+y)+1-1/40*x.^2+exp(-y.^2)','x','y')
x=-6:.2:9
y=-4:.2:4
[x,y]=meshgrid(x,y);
surf(x,y,f(x,y))

>> Untitled

f=

Inline function:

f(x,y) = sin(x+y)+1-1/40*x.^2+exp(-y.^2)

x=

Columns 1 through 12

-6.0000 -5.8000 -5.6000 -5.4000 -5.2000 -5.0000 -4.8000 -4.6000 -4.4000


-4.2000 -4.0000 -3.8000

Columns 13 through 24

-3.6000 -3.4000 -3.2000 -3.0000 -2.8000 -2.6000 -2.4000 -2.2000 -2.0000


-1.8000 -1.6000 -1.4000

Columns 25 through 36
-1.2000 -1.0000 -0.8000 -0.6000 -0.4000 -0.2000 0 0.2000 0.4000
0.6000 0.8000 1.0000

Columns 37 through 48

1.2000 1.4000 1.6000 1.8000 2.0000 2.2000 2.4000 2.6000 2.8000


3.0000 3.2000 3.4000

Columns 49 through 60

3.6000 3.8000 4.0000 4.2000 4.4000 4.6000 4.8000 5.0000 5.2000


5.4000 5.6000 5.8000

Columns 61 through 72

6.0000 6.2000 6.4000 6.6000 6.8000 7.0000 7.2000 7.4000 7.6000


7.8000 8.0000 8.2000

Columns 73 through 76

8.4000 8.6000 8.8000 9.0000

y=

Columns 1 through 12

-4.0000 -3.8000 -3.6000 -3.4000 -3.2000 -3.0000 -2.8000 -2.6000 -


2.4000 -2.2000 -2.0000 -1.8000

Columns 13 through 24

-1.6000 -1.4000 -1.2000 -1.0000 -0.8000 -0.6000 -0.4000 -0.2000 0


0.2000 0.4000 0.6000

Columns 25 through 36

0.8000 1.0000 1.2000 1.4000 1.6000 1.8000 2.0000 2.2000 2.4000


2.6000 2.8000 3.0000

Columns 37 through 41

3.2000 3.4000 3.6000 3.8000 4.0000


Figure VII

Application13:
>> A=[6 1 -5;2 2 3;4 -9 7]

A=

6 1 -5

2 2 3

4 -9 7

>> B=[6;7;10]

B=

10

>> x=inv(A)*B

x=

1.7166
0.3797

0.9358

>> A=[1 2 3 4;2 3 4 1;-2 4 -5 2;8 1 -1 3]

A=

1 2 3 4

2 3 4 1

-2 4 -5 2

8 1 -1 3

>> B=[2;0;3;4]

B=

>> x=inv(A)*B

x=

0.2000

0.1000

-0.3385

0.6538

Conclusion:
A partir de ce TP on a conclu que nous pouvons utiliser ce logiciel dans :

- La manipulation des données.

- Les différents calculs matriciels.

- La Résolution d’équations linéaires et non linéaires.

- La représentation graphique des fonctions.

Vous aimerez peut-être aussi