{"id":41,"date":"2020-12-02T20:27:03","date_gmt":"2020-12-02T20:27:03","guid":{"rendered":"http:\/\/med-space.org\/youssef-zaz-master\/?page_id=41"},"modified":"2020-12-06T12:36:57","modified_gmt":"2020-12-06T12:36:57","slug":"matlab-matrice","status":"publish","type":"page","link":"https:\/\/yzaz.net\/master\/matlab-matrice\/","title":{"rendered":"Matlab &#8211; Manipulation des matrices"},"content":{"rendered":"<h3>Attribuer une valeur \u00e0 une variable<\/h3>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nA=3\r\n<\/pre>\n<pre>A =\r\n     3\r\n<\/pre>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nB=5\r\n<\/pre>\n<pre>B =\r\n     5\r\n<\/pre>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nC=A\/B\r\n<\/pre>\n<pre>C =\r\n    0.6000\r\n<\/pre>\n<p>Pour recup\u00e9rer la taille de memoire occup\u00e9e par les variables:<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nwhos\r\n<\/pre>\n<pre>  Name      Size            Bytes  Class     Attributes\r\n\r\n  A         1x1                 8  double              \r\n  B         1x1                 8  double              \r\n  C         1x1                 8  double              \r\n<\/pre>\n<p>Pour recup\u00e9rer les variables utilis\u00e9es:<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nwho\r\n<\/pre>\n<pre>Your variables are:\r\nA  B  C  \r\n<\/pre>\n<h3>Attribuer des valeurs \u00e0 des vecteurs et des matrices<\/h3>\n<p><b>Attribution des valeurs \u00e0 un vecteur:<\/b><\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nV = [4 2 4 3 7]\r\n<\/pre>\n<pre>V =\r\n     4     2     4     3     7\r\n<\/pre>\n<p>Dans un vecteur de ligne, les valeurs sont s\u00e9par\u00e9es par des espaces.<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nW = [9;2;9;15;12]\r\n<\/pre>\n<pre>W =\r\n     9\r\n     2\r\n     9\r\n    15\r\n    12\r\n<\/pre>\n<p>Dans un vecteur de colonne, les valeurs sont s\u00e9par\u00e9es par un point-virgule (;)<\/p>\n<p><b>Attribution des valeurs \u00e0 une matrice:<\/b><\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nM = [1 2 3 6; 5 5 6 4; 6 -9 2 -1]\r\n<\/pre>\n<pre>M =\r\n     1     2     3     6\r\n     5     5     6     4\r\n     6    -9     2    -1\r\n<\/pre>\n<p>Transpose d&#8217;une matrice ou d&#8217;un vecteur:<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nN=M'\r\n<\/pre>\n<pre>N =\r\n     1     5     6\r\n     2     5    -9\r\n     3     6     2\r\n     6     4    -1\r\n<\/pre>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nd =1:10 \r\n<\/pre>\n<pre>d =\r\n     1     2     3     4     5     6     7     8     9    10\r\n<\/pre>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nk =2:-0.5:-1 \r\n<\/pre>\n<pre>k =\r\n    2.0000    1.5000    1.0000    0.5000      0   -0.5000   -1.0000\r\n<\/pre>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nl = [1:4; 5:8 ; 11:14]\r\n<\/pre>\n<pre>l =\r\n     1     2     3     4\r\n     5     6     7     8\r\n    11    12    13    14\r\n<\/pre>\n<p>Cr\u00e9ation d&#8217;une matrice des z\u00e9ros:<\/p>\n<p>zeros(M,N) avec M et N la dimension de la matrice<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nA=zeros(4,5)\t\r\n<\/pre>\n<pre>A =\r\n     0     0     0     0     0\r\n     0     0     0     0     0\r\n     0     0     0     0     0\r\n     0     0     0     0     0\r\n<\/pre>\n<p>Cr\u00e9ation d&#8217;une matrice des uns:<br \/>\nones(M,N) avec M et N la dimension de la matrice<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nB=ones(4,6)\t\r\n<\/pre>\n<pre>B =\r\n     1     1     1     1     1     1\r\n     1     1     1     1     1     1\r\n     1     1     1     1     1     1\r\n     1     1     1     1     1     1\r\n<\/pre>\n<p><b>G\u00e9n\u00e9ration d&#8217;une matrice des chiffres al\u00e9atoires:<\/b><\/p>\n<p>rand(M,N) avec M et N la dimension de la matrice<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nC=rand(4,4)\r\n<\/pre>\n<pre>C =\r\n    0.6787    0.6555    0.2769    0.6948\r\n    0.7577    0.1712    0.0462    0.3171\r\n    0.7431    0.7060    0.0971    0.9502\r\n    0.3922    0.0318    0.8235    0.0344\r\n<\/pre>\n<p><b>Indices dans les matrices<\/b><br \/>\nL\u2019indice dans Matlab commence par 1, non pas par 0 comme la quasi-totalit\u00e9 des logiciels de programmation.<br \/>\nSupposant qu&#8217;on a la matrice M suivante:<\/p>\n<pre>M =\r\n     1     2     3     6\r\n     5    11     7     4\r\n    12    -9     2    -1\r\n<\/pre>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nM(6)\r\n<\/pre>\n<pre>ans =\r\n    -9\r\n<\/pre>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nM(3,:)\r\n<\/pre>\n<pre>ans =\r\n    12    -9     2    -1\r\n<\/pre>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nM(1:3,2)\r\n<\/pre>\n<pre>\r\nans =\r\n     2\r\n    11\r\n    -9\r\n<\/pre>\n<p>Les indices doivent \u00eatre des entiers positifs et de valeur logique.<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nM(-1)\r\n<\/pre>\n<pre>\r\n<span style=\"color: red;\">Index exceeds matrix dimensions.<\/span>\r\n<\/pre>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nM(5,2)\r\n<\/pre>\n<pre>\r\n<span style=\"color: red;\">Index exceeds matrix dimensions.<\/span>\r\n<\/pre>\n<p><b>Concatenation des matrices<\/b><\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nA = [1 2 3],  B = [8 7 5], C=[ 2 -1 3]\r\nU = [A B]\r\nV = [A ; B]\r\n<\/pre>\n<pre>\r\nA =\r\n     1     2     3\r\n\r\nB =\r\n     8     7     5\r\n\r\nC =\r\n     2    -1     3\r\n\r\nU =\r\n     1     2     3     8     7     5\r\n\r\nV =\r\n     1     2     3\r\n     8     7     5\r\n<\/pre>\n<p>Une matrice peut \u00eatre index\u00e9e \u00e0 l&#8217;aide d&#8217;une autre matrice, pour produire un sous-matrice de ses \u00e9l\u00e9ments.<br \/>\nExemple:<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nA = [50 20 40 70 90 80 30],     B = [2 5 6]\r\nC = A(B)\r\n<\/pre>\n<pre>\r\nA =\r\n    50    20    40    70    90    80    30\r\n\r\nB =\r\n     2     5     6\r\n\r\nC =\r\n    20    90    80\r\n<\/pre>\n<p><b>Op\u00e9ration arithmetique<\/b><br \/>\n+   Addition<br \/>\n&#8211;   Soustraction<br \/>\n*   Multiplication<br \/>\n\/   Division<br \/>\n^   Puissance<br \/>\n&#8216;   Transpos\u00e9<\/p>\n<p>Exemples:<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nA = [1 2 3 ; 5 5 6 ; 6  3 -1]\r\nB = [4 3 1 ; 2 7 8 ; 5  2 4]\r\nC = A + B    % Addition\r\nD = A - B    % Soustraction\r\nE = A * B    % Multiplication. Nombre de ligne de A = Nombre de colonne de B \r\nG = A \/ B    % la matrice B doit \u00eatre inversible\r\nH = inv (A)  % La matrice inverse\r\nF= A'        % la matrice Transpos\u00e9e\r\n<\/pre>\n<pre>\r\nA =\r\n     1     2     3\r\n     5     5     6\r\n     6     3    -1\r\n\r\nB =\r\n     4     3     1\r\n     2     7     8\r\n     5     2     4\r\n\r\nC =\r\n     5     5     4\r\n     7    12    14\r\n    11     5     3\r\n\r\nD =\r\n    -3    -1     2\r\n     3    -2    -2\r\n     1     1    -5\r\n\r\nE =\r\n    23    23    29\r\n    60    62    69\r\n    25    37    26\r\n\r\nG =\r\n   -0.1504    0.2920    0.2035\r\n    0.3009    0.4159    0.5929\r\n    1.7611   -0.3009   -0.0885\r\n\r\nH =\r\n   -1.6429    0.7857   -0.2143\r\n    2.9286   -1.3571    0.6429\r\n   -1.0714    0.6429   -0.3571\r\n\r\nF =\r\n     1     5     6\r\n     2     5     3\r\n     3     6    -1\r\n<\/pre>\n<p><b>Op\u00e9rateurs \u00e9l\u00e9ment par \u00e9l\u00e9ment<\/b><br \/>\n.*   Multiplication \u00e9l\u00e9ment par \u00e9l\u00e9ment<br \/>\n.\/   Division \u00e9l\u00e9ment par \u00e9l\u00e9ment<br \/>\n.^   Puissance \u00e9l\u00e9ment par \u00e9l\u00e9ment<\/p>\n<p>Exemple: <\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nA = [1 2 3 ; 5 5 6 ; 6  3 -1]\r\nB = [4 3 1 ; 2 7 8 ; 5  2 4]\r\nC = A .* B\r\nD = A .\/ B\r\nE = A .^ B\r\n<\/pre>\n<pre>\r\nA =\r\n     1     2     3\r\n     5     5     6\r\n     6     3    -1\r\n\r\nB =\r\n     4     3     1\r\n     2     7     8\r\n     5     2     4\r\n\r\nC =\r\n\r\n     4     6     3\r\n    10    35    48\r\n    30     6    -4\r\n\r\nD =\r\n    0.2500    0.6667    3.0000\r\n    2.5000    0.7143    0.7500\r\n    1.2000    1.5000   -0.2500\r\n\r\nE =\r\n           1           8           3\r\n          25       78125     1679616\r\n        7776           9           1\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Attribuer une valeur \u00e0 une variable A = 3 B = 5 C = 0.6000 Pour recup\u00e9rer la taille de memoire occup\u00e9e par les variables: <a class=\"mh-excerpt-more\" href=\"https:\/\/yzaz.net\/master\/matlab-matrice\/\" title=\"Matlab &#8211; Manipulation des matrices\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":200,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"_links":{"self":[{"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/pages\/41"}],"collection":[{"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/comments?post=41"}],"version-history":[{"count":34,"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/pages\/41\/revisions"}],"predecessor-version":[{"id":81,"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/pages\/41\/revisions\/81"}],"wp:attachment":[{"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/media?parent=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}