Fonctions de base

Transcription

Fonctions de base
SI101 / Janvier 2010 / GB/BD
1
◦ Commandes de base
− whos : List current variables, and their size.
− clear : Clear variables and functions from memory.
− save : Save workspace variables to disk. Exemple : save mesdonnees a b x sauvegarde a, b et x
dans le fichier mesdonnees.mat. Faire attention aux problèmes de version !
− load : Load workspace variables from disk. Exemple : load mesdonnees recharge les données
sauvegardées précédemment.
− exit : Exit from MATLAB.
− cd : Change current working directory.
− delete : Delete file or graphics object.
− pwd : Show (print) current working directory.
− dir ou ls : List directory.
On peut invoquer les commandes du système d’exploitation de la machine (shell) avec le point
d’exclamation suivi de la commande. Exemple : !ls -l *.m.
◦ Opérations de base sur les matrices et vecteurs
* : multiplication au sens de l’algèbre. Les dimensions doivent être compatibles.
A=[1,2;3,4;5,6]; x=[1;2]; y=A*x.
.* : multiplication pointée
A .* B donne la matrice [aij × bij ].
+, - : addition, soustraction
/ ou mrdivide : division à droite
A / B donne A × B −1 .
\ ou mldivide : division à gauche
A \ B donne A−1 × B.
./ ou rdivide : division à droite pointée
.\ ou ldivide : division à gauche pointée
◦ Arrondis et fonctions standards
−fix : Round towards zero.
−mod : Modulus (signed remainder after division).
−floor : Round towards minus infinity.
−rem : Remainder after division.
−ceil : Round towards plus infinity.
−sign : Signum
−round : Round towards nearest integer.
−sin, cos, log, exp, log10 : fonctions... log10(A)
donne [log10 (aij )].
−log2, pow2, nextpow2, sqrt : fonctions...
◦ Fonctions sur complexes
’ ou ctranspose : Hermitian transpose.
.’ ou transpose : Transpose.
abs : Absolute value.
angle : Phase angle.
conj : Complex conjugate.
imag : Imaginary part.
real : Real part.
SI101 / Janvier 2010 / GB/BD
2
◦ Structures de programmes
− if : Conditionally execute statements. Les opérateurs booléens sont ~=, ==, |, &...
− else : Execute statement if previous IF condition failed.
− elseif : Execute if previous IF failed and condition is true.
− end : Terminate scope of control statements.
− for : Repeat statements a specific number of times. Exemple : for k=1:10, x(k)=k; end.
− while : Repeat statements an indefinite number of times.
− break : Terminate execution of WHILE or FOR loop.
− continue : Pass control to the next iteration of a loop.
− switch, case, otherwise : Switch among several cases based on expression. Exemple : rep=’non’;
switch rep, case ’oui’, y=0, case ’non’, y=1, otherwise, y=2, end.
− return : Return to invoking function.
◦ Constantes et matrices prédéfinies et fonctions de base
pi, i, j, 1i, 1j, eps, realmin, realmax, intmax,
intmin : constantes.
zeros : Zeros array.
ones : Ones array.
eye : Identity matrix.
rand et randi : Uniformly distributed random real
and integer numbers respectively.
randn : Normally distributed random numbers.
compan : Companion matrix.
toeplitz, hankel... : toeplitz, hankel matrix...
“:” : Regularly spaced vector and index into matrix. Exemple : x, x(:) et x(1:end) désignent le
vecteur x.
size : Size of array.
length : Length of vector.
disp : Display matrix or text.
reshape : Change size.
diag : Diagonal matrices and diagonals of matrix.
fliplr, flipud : Flip matrix in left/right and
up/down direction respectively.
rot90 : Rotate matrix 90 degrees.
end : Last index.
find : Find indices of nonzero elements. Exemple :
idx=find(A<0) retourne les indices des éléments
négatifs de A. A(idx)=0 remet tous ces éléments à
0.
SI101 / Janvier 2010 / GB/BD
3
◦ Fonctions de l’algèbre linéaire
norm : Matrix or vector norm.
rank : Matrix rank.
det : Determinant.
trace : Sum of diagonal elements.
inv, pinv : inverse and pseudo-inverse matrix.
eig : Eigenvalues and eigenvectors.
svd : Singular value decomposition.
poly : Characteristic polynomial.
roots : Find polynomial roots.
expm : Matrix exponential. Ne pas confondre avec
exp(A) qui donne [exp(aij )].
logm : Matrix logarithm. Ne pas confondre avec
log(A) qui donne [ln(aij )].
sqrtm : Matrix square root.
funm : Evaluate general matrix function.
max : Largest component. Exemple : max(max(A))
donne maxi,j aij .
min : Smallest component.
◦ Time series and polynomial functions
hist : Histogram.
stem : Discrete sequence or ”stem” plot.
mean : Average or mean value.
median : Median value.
std : Standard deviation.
var : Variance.
sort : Sort in ascending order.
sum : Sum of elements. Exemple sum(A) où A est
(n × m) donne un vecteur (1 × m) des somme effectuées sur les éléments des colonnes.
prod : Product of elements.
diff : Difference and approximate derivative.
filter, filter2 : 1-D and 2-D digital filter respectively.
conv, conv2 : 1-D and 2-D Convolution and polynomial multiplication respectively.
◦ Transformée de Fourier discrète
− fft, ifft : Discrete Fourier transform and Inverse DFT respectively.
− fft2, ifft2 : Two-dimensional discrete Fourier transform and 2-D DFT respectively.
◦ Figure window creation and control
figure : Create figure window.
gcf : Get handle to current figure.
clf : Clear current figure.
close : Close figure.
◦ Elementary X-Y graphs
−plot : Linear plot. Exemple : soit t=[0:100];
f0=.1; xt=sin(2*pi*f0*t));.
plot(xt),
plot(t,xt), plot(t,xt,’-r’,t,xt,’o’)...
−subplot : Create axes in tiled positions. Exemple : x=[0:10]; subplot(2,3,1), plot(x),
subplot(235), plot(x,’x’).
−axis : Control axis scaling and appearance.
−title : Graph title.
−zoom : Zoom in and out on a 2-D plot. Exemples :
zoom xon, zoom off...
−xlabel, ylabel : X-axis and Y-axis label.
−hold : Hold current graph. Utiliser hold on et
hold off.
−text, gtext : Text annotation and interactive
text annotation.
−grid : Grid lines.
−axes : Create axes in arbitrary positions.
SI101 / Janvier 2010 / GB/BD
4
◦ Fonctions Audio
− sound et soundsc : Play vector as sound and Autoscale and play vector as sound.
− wavplay : Play sound using Windows audio output device.
− wavrecord : Record sound using Windows audio input device.
− auread, auwrite : Read and write respectively NeXT/SUN (”.au”) sound file.
− wavread, wavwrite : Read and write respectively Microsoft WAVE (”.wav”) sound file.
− aviread, avifile : Read and create respectively movie (AVI) file.
◦ Images display and file I/O
− image : Display image.
− imagesc : Scale data and display as image.
− colormap : Color look-up table. Exemple colormap(’gray’) définit une table de niveaux de gris.
− imread, imwrite : Read and write respectively image from graphics file.
◦ Manipulation de chaı̂nes de caractères
char : Create character array (string).
blanks : String of blanks.
deblank : Remove trailing blanks.
strcat : Concatenate strings.
strvcat : Vertically concatenate strings.
strcmp : Compare strings.
strncmp : Compare first N characters of strings.
strcmpi : Compare strings ignoring case.
strncmpi : Compare first N characters of strings
ignoring case.
findstr et strfind : Find one string within another.
strrep : Replace string with another.
strtrim : Remove insignificant whitespace.
upper : Convert string to uppercase.
lower : Convert string to lowercase.
num2str : Convert numbers to a string.
int2str : Convert integer to string.
mat2str : Convert a 2-D matrix to a string in
MATLAB syntax.
str2double : Convert string to double precision
value.
str2num : Convert string matrix to numeric array.
sprintf : Write formatted data to string.
sscanf : Read string under format control.
hex2num : Convert hexadecimal string to double
precision number.
hex2dec : Convert hexadecimal string to decimal
integer.
dec2hex : Convert decimal integer to hexadecimal
string.
bin2dec : Convert binary string to decimal integer.
dec2bin : Convert decimal integer to a binary
string.
base2dec : Convert base B string to decimal integer.
dec2base :
string.
num2hex : Convert singles and doubles to IEEE
hexadecimal strings.
Convert decimal integer to base B