0% ont trouvé ce document utile (0 vote)
31 vues20 pages

Devoir MATLAB : Exercices et Résultats

Ce document contient des exercices sur l'utilisation de Matlab. Il présente plusieurs commandes et fonctions comme la création et manipulation de matrices, le calcul de sommes, moyennes, écart-types, produits scalaires, déterminants, inverses et résolutions de systèmes linéaires.

Transféré par

Belinda Dancheu
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats DOCX, PDF, TXT ou lisez en ligne sur Scribd
0% ont trouvé ce document utile (0 vote)
31 vues20 pages

Devoir MATLAB : Exercices et Résultats

Ce document contient des exercices sur l'utilisation de Matlab. Il présente plusieurs commandes et fonctions comme la création et manipulation de matrices, le calcul de sommes, moyennes, écart-types, produits scalaires, déterminants, inverses et résolutions de systèmes linéaires.

Transféré par

Belinda Dancheu
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats DOCX, PDF, TXT ou lisez en ligne sur Scribd

DEVOIR MATLAB 

:
Exercice 1 :
1.
 Non
 Oui
 Non
 Non
 Oui
 Non
 Non
 Non

2.
>> ceil(B)-floor(B)

ans =

1 0
1 1

>> B=floor(B)

B=
1 -2
0 1

>> [A,A]'

ans =

-1 3 0
1 0 2
-1 3 0
1 0 2

>> A.*(2*ones(3,2))

ans =

-2 2
6 0
0 4

>> A+(2+zeros(3,2))
ans =

1 3
5 2
2 4

>> A==[-1,1;2,4;0,5]

ans =

1 1
0 0
1 0

Exercice 2 :
1. Calculons les expressions :
>> A*B-3

ans =

0 -3
18 -15

>> A.*B-3
ans =

0 -7
-3 -1

>> A^2-ones(2)

ans =

14 5
20 17

>> C*B + 1+zeros(4,2)

ans =

-2 6
1 2
-2 2
13 1

>> A'.^B/2

ans =

0.5000 0.0102
0.5000 1.0000

Did you mean:


>> C*eye(2)

ans =

-1 3
0 1
-1 -1
4 8

>> C(1:2,:)^2

ans =

1 0
0 1

>> C

C=

-1 3
0 1
-1 -1
4 8

>> C(2:3,:).^2

ans =

0 1
1 1

>> C(end:-1:1,2).\24

ans =

3
-24
24
8
2. Créons la matrice M :

>> M=[[A;B],C]

M=

1 2 -1 3
7 2 0 1
3 -2 -1 -1
0 1 4 8

3. Donnons les résultats pour chacune des commandes :

>> M(3,2)=3

M=

1 2 -1 3
7 2 0 1
3 3 -1 -1
0 1 4 8

>> M(3,[2 4])

ans =

3 -1

>> M(1:3,[2 4])

ans =

2 3
2 1
3 -1
>> M(1:3,[2 4])'

ans =

2 2 3
3 1 -1

>> M(2,:)-7*M(1,:)

ans =

0 -12 7 -20

>> M(2,:)= M(2,:)-7*M(1,:)

M=

1 2 -1 3
0 -12 7 -20
3 3 -1 -1
0 1 4 8

>> M([1 3],[1 3])=10*ones(2)

M=

10 2 10 3
0 -12 7 -20
10 3 10 -1
0 1 4 8

>> M([1,3],:)=[]

M=
0 -12 7 -20
0 1 4 8

>> M(:,1)=[]

M=

-12 7 -20
1 4 8

>> size(M)*M

ans =

-21 26 -16

>> M(end:-1:1,end:-2:1)

ans =

8 1
-20 -12

>> M=[[M;M] ones(4,1)]

M=

-12 7 -20 1
1 4 8 1
-12 7 -20 1
1 4 8 1

>> tril(M,-1)+triu(M,2)
ans =

0 0 -20 1
1 0 0 1
-12 7 0 0
1 4 8 0

Exercice 3 :

1.
N= input('entrez un nombre entier positif: ') ;
F=1;
for i= 1:N
F=F*i;

end
disp(F)
en entrant les chiffres 5,3 et 4 on obtient :

>> Untitled
entrez un nombre entier positif: 5
120

>> Untitled
entrez un nombre entier positif: 3
6

>> Untitled
entrez un nombre entier positif: 4
24

2. Ce programme calcul le factoriel d’un nombre


3.
N= input('entrez un nombre entier positif: ');
F=1;
while (o<=N)
o= input('entrez un nombre entier positif: ') ;
F=F*o
end
disp(F)

Exercice 4 :
1. Structures Matlab :
a) Entrons les données dans Matlab :
>> U1=[1;2;3],U2=[-5;2;1],U3=[-1;-3;7],A=[2,3,4;7,6,5;2,8,7]

U1 =

1
2
3

U2 =

-5
2
1

U3 =

-1
-3
7

A=

2 3 4
7 6 5
2 8 7
b) Calculons :

>> U1+3*U2-U3/5

ans =

-13.8000
8.6000
4.6000
c) Calculons le produit scalaire :
dot(U1,U2)
ans =

2
Calculons le produit :
>> A*U1

ans =

20
34
39
2. Commandes Matlab :
a)

>> norm(U1)*2,norm(U2)*1,norm(U3)*inf

ans =

7.4833

ans =

5.4772

ans =

Inf
b)
>> size(A)

ans =
3 3
c)
>> det(A),inv(A)

ans =

63.0000

ans =

0.0317 0.1746 -0.1429


-0.6190 0.0952 0.2857
0.6984 -0.1587 -0.1429

3. Résolution des problèmes linéaires :


Pour résoudre ce problème on pourrait :
 Multiplié les côtés de l’égalité par l’inverse de A et ainsi on obtient le
vecteur X
>> X=inv(A)*U1

X=

-0.0476
0.4286
-0.0476.
Exercice 5 :
1. Créons le vecteur x :
x=[17,8,12,15,6,11,9,18,16,10,13,19]

x=

17 8 12 15 6 11 9 18 16 10 13 19
2. Calculons la longueur de x :
>> N=length(x)

N=

12
3. Calculons la somme des éléments :
>> S=sum(x)

S=

154
4. Calculons la moyenne des éléments :
>> mean(x)

ans =

12.8333
5. Calculons l’écart type :
ecart =

4.0173
6. Calculons le vecteur dx :
dx =
6 .
Exercice 6 :
1. Définissons le vecteur t :
>> t=linspace(-25,25,51)

t=

Columns 1 through 16

-25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -
10

Columns 17 through 32

-9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6

Columns 33 through 48

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

Columns 49 through 51

23 24 25
2. Calculons le vecteur x=t² :
>> x=t.^2

x=

Columns 1 through 16

625 576 529 484 441 400 361 324 289 256 225 196 169 144
121 100

Columns 17 through 32
81 64 49 36 25 16 9 4 1 0 1 4 9 16 25 36

Columns 33 through 48

49 64 81 100 121 144 169 196 225 256 289 324 361 400
441 484

Columns 49 through 51

529 576 625


3. Calculons le vecteur y :

>> y=fliplr(t.^3)

y=

Columns 1 through 7

15625 13824 12167 10648 9261 8000 6859

Columns 8 through 14

5832 4913 4096 3375 2744 2197 1728

Columns 15 through 21

1331 1000 729 512 343 216 125

Columns 22 through 28

64 27 8 1 0 -1 -8

Columns 29 through 35

-27 -64 -125 -216 -343 -512 -729


Columns 36 through 42

-1000 -1331 -1728 -2197 -2744 -3375 -4096

Columns 43 through 49

-4913 -5832 -6859 -8000 -9261 -10648 -12167

Columns 50 through 51

-13824 -15625
4. Représentons x et y en fonction de t :
5. Calculons la somme des éléments paires de x :

S = 5200
6. Calculons la somme des éléments positifs de y :
S = 105625

Exercice 7 :
1. Créons une fonction t :
A=input('entrez une matrice: ');
if (size(A,1)==size(A,2))
trace (A)
else
disp(-1)
end
2. Générons une matrice :
rand(10,10)

ans =

Columns 1 through 9

0.8147 0.1576 0.6557 0.7060 0.4387 0.2760 0.7513 0.8407


0.3517
0.9058 0.9706 0.0357 0.0318 0.3816 0.6797 0.2551 0.2543
0.8308
0.1270 0.9572 0.8491 0.2769 0.7655 0.6551 0.5060 0.8143
0.5853
0.9134 0.4854 0.9340 0.0462 0.7952 0.1626 0.6991 0.2435
0.5497
0.6324 0.8003 0.6787 0.0971 0.1869 0.1190 0.8909 0.9293
0.9172
0.0975 0.1419 0.7577 0.8235 0.4898 0.4984 0.9593 0.3500
0.2858
0.2785 0.4218 0.7431 0.6948 0.4456 0.9597 0.5472 0.1966
0.7572
0.5469 0.9157 0.3922 0.3171 0.6463 0.3404 0.1386 0.2511
0.7537
0.9575 0.7922 0.6555 0.9502 0.7094 0.5853 0.1493 0.6160
0.3804
0.9649 0.9595 0.1712 0.0344 0.7547 0.2238 0.2575 0.4733
0.5678

Column 10

0.0759
0.0540
0.5308
0.7792
0.9340
0.1299
0.5688
0.4694
0.0119
0.3371
3. Calculons la trace d’une matrice, de sa transposée et de son inverse  :
>> trace(s),trace(s'),trace(inv(s))

ans =

4.6543

ans =

4.6543

ans =

-0.3959

Common questions

Alimenté par l’IA

MATLAB's trigonometric (e.g., sin, cos) and power functions accentuate computational relationships by manipulating matrices to showcase cyclical or exponential data patterns. For instance, squaring matrices or applying sin(A) can reveal periodicity or growth behaviors. By amplifying particular data characteristics, these functions allow for an exploration of underlying mathematical relationships and visual representation of data cycles .

Vector x is derived by squaring each element of vector t using element-wise operations. This conversion facilitates further evaluations, such as statistical analysis or simulations, by transforming linear data into a quadratic format, enriching the data model. It allows exploration of quadratic behaviors and provides a manipulated dataset that can reveal different insights or inform more complex simulations .

The linspace function generates a vector t by specifying the start, end, and number of points, creating evenly spaced elements. This method is particularly useful for generating vectors with defined intervals, facilitating precise calculations and plotting. It standardizes data points across a specific range, aiding in subsequent vector operations like squaring or reversing elements efficiently .

MATLAB functions utilize loops and conditional structures to handle repetitive computations and decision-making logic. Loops process sequences of operations to build results iteratively (e.g., calculating factorials with for-loops), while conditional structures (if-else) evaluate conditions to guide program flows based on input (e.g., checking matrix squareness before trace calculation). By differentiating usage according to operation type and required outputs, MATLAB optimizes for efficiency and accuracy .

The factorial calculation program, which uses a for loop (F=1; for i=1:N F=F*i; end), ensures correct functionality by initializing the result variable F to 1 and iteratively multiplying it by each integer up to N. This use of iteration builds the factorial value progressively, hence it guarantees that F will contain the factorial of N if a valid positive integer N is consistently inputted .

Matrix M can be modified in several ways: changing specific elements (e.g., M(3,2)=3 or M(3,[2 4]) leads to adjusted specific entries), row operations (e.g., M(2,:)-7*M(1,:) replaces the second row with the result of the operation), and removal of rows or columns (e.g., M([1,3],:) = [] removes specified rows, and M(:,1)=[] removes the first column). Each operation affects the dimensions or specific entries of M, altering its properties such as rank or determinant .

U1's integrity during operations is preserved by handling operations according to type: scalar operations scale all elements equally (e.g., norm(U1)*2 maintains vector proportions), and vector operations (e.g., U1+3*U2) ensure element-wise calculations align dimensional compatibility. MATLAB's inherent operational checks prevent incompatible operations, thereby maintaining U1's computational integrity .

To solve linear equations, matrix A can be used to find the solution to A*X=U1 by multiplying both sides by the inverse of A. Calculating X=inv(A)*U1 provides the solution vector X by effectively isolating X on one side of the equation using the property of matrix inverses where A*inv(A)=I (identity matrix).

To calculate the trace of a matrix, including its transpose or inverse, one must ensure the matrix is square. MATLAB's trace function computes the sum of diagonal elements. For example, using trace(M) gives you the matrix's trace, while trace(M') or trace(inv(M)) does the same for its transpose and inverse, respectively. The functionality checks for matrix dimensionality consistency to prevent errors .

Element-wise operations (e.g., A.*B) apply calculations independently to corresponding elements across matrices, denoted by the '.*' operator. In contrast, matrix-wise operations (e.g., A*U1) perform algebraic matrix multiplication, calculating dot products between rows and columns. Procedurally, this involves different operator notations and impacts computational results by changing the focus from individual element processing to structural interactions across entire matrices .

Vous aimerez peut-être aussi