Mathc matrices/04g
Apparence
Réécrire le code de quelques fonctions
[modifier | modifier le wikicode]- Matrice diagonale
- Matrice Triangulaire inférieure
- Matrice triangulaire supérieure
- Matrice symétrique
- Matrice antisymétrique
Diagonal matrix
[modifier | modifier le wikicode]Copy/Paste into the octave window
%% Diagonal matrix
%%
%% Clear all user-defined variables
clear
%% ----------------------- */
%% ----------------------- */
function M = diagD(M)
r = size (M, 1);
%% Diagonal matrix
for i=1:r
M(i,i) = round(10*randn());
end
endfunction
%% ----------------------- */
%% ----------------------- */
%%
%% === main ===
%% Clear the terminal
clc
rc = 6;
A = zeros(rc);
%% Display A
A = diagD(A)
%% Display A as an indexed color image
figure(1), clf
imagesc(A)
axis square, title('A')
%% === return(0) ===
Lower triangular matrix
[modifier | modifier le wikicode]Copy/Paste into the octave window
%% Lower triangular matrix
%%
%% Clear all user-defined variables
clear
%% ----------------------- */
%% ----------------------- */
function M = trigL(M)
[r,c] = size (M);
%% Lower triangular matrix
for i=1:r
for j=1:c
if((i>=j))
M(i,j) = round(10*randn());
endif
end
end
endfunction
%% ----------------------- */
%% ----------------------- */
%%
%% === main ===
%% Clear the terminal
clc
r = 6;
c = 6;
A = zeros(r,c);
%% Display A
A = trigL(A)
%% Display A as an indexed color image
figure(1), clf
imagesc(A)
axis square, title('A')
%% === return(0) ===
Upper triangular matrix
[modifier | modifier le wikicode]Copy/Paste into the octave window
%% Upper triangular matrix
%%
%% Clear all user-defined variables
clear
%% ----------------------- */
%% ----------------------- */
function M = trigU(M)
[r,c] = size (M);
%% Upper triangular matrix
for i=1:r
for j=1:c
if((i<=j))
M(i,j) = round(10*randn());
endif
end
end
endfunction
%% ----------------------- */
%% ----------------------- */
%%
%% === main ===
%% Clear the terminal
clc
r = 6;
c = 6;
A = zeros(r,c);
%% Display A
A = trigU(A)
%% Display A as an indexed color image
figure(1), clf
imagesc(A)
axis square, title('A')
%% === return(0) ===
Symmetric matrix
[modifier | modifier le wikicode]Copy/Paste into the octave window
%% Symmetric matrix
%%
%% Clear all user-defined variables
clear
%% ----------------------- */
%% ----------------------- */
function M = symmetric(M)
[r,c] = size (M);
%% Symmetric matrix
for i=1:r
for j=1:c
x = round(10*randn());
M(i,j) = x;
M(j,i) = x;
end
end
endfunction
%% ----------------------- */
%% ----------------------- */
%%
%% === main ===
%% Clear the terminal
clc
r = 6;
c = 6;
A = zeros(r,c);
%% Display A
A = symmetric(A)
%% Display A as an indexed color image
figure(1), clf
imagesc(A)
axis square, title('A')
%% === return(0) ===
Skewsymmetric matrix
[modifier | modifier le wikicode]Copy/Paste into the octave window
%% Skewsymmetric matrix
%%
%% Clear all user-defined variables
clear
%% ----------------------- */
%% ----------------------- */
function M = skewsymmetric(M)
[r,c] = size (M);
%% Skewsymmetric matrix
for i=1:r
for j=1:c
if (i==j)
M(i,j) = 0;
else
x = round(10*randn());
M(i,j) = x;
M(j,i) = -x;
endif
end
end
endfunction
%% ----------------------- */
%% ----------------------- */
%%
%% === main ===
%% Clear the terminal
clc
r = 6;
c = 6;
A = zeros(r,c);
%% Display A
A = skewsymmetric(A)
%% Display A as an indexed color image
figure(1), clf
imagesc(A)
axis square, title('A')
%% === return(0) ===