MATLAB POLYSPACE RELEASE NOTES Instrukcja Użytkownika Strona 161

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 240
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 160
Scripts and Functions
% independent rows or c olumns of a mat rix A.
% RANK(A,tol) is the nu mber of singular values of A
% that are larger than tol.
% RANK(A) uses the default tol = max(size(A)) * norm(A) * eps.
s = svd(A);
if nargin==1
tol = max(size(A)') * max(s) * eps;
end
r = sum(s > tol);
The first line of a function M -file starts with the keyword function.Itgives
the function name and order of arguments. In this case, there are up to two
input arguments and one output argument.
Thenextseverallines,uptothefirstblankorexecutableline,arecomment
lines that provide the help text. These lines are printed when you type
help rank
The first line of the help text is the H1 line, which M ATLAB displays when
you use the
lookfor command or reques t help on a directory.
TherestofthefileistheexecutableMATLABcodedefiningthefunction.The
variable
s introduced in the body of the function, as well as the variables on
the first line,
r, A and tol,arealllocal to the function; they are separate from
any variables in the MATLAB workspace.
This example illustrates one aspect of MATLAB functions that is not
ordinarily found in other programming languages—a variable number of
arguments. The
rank function can be used in several different ways:
rank(A)
r = rank(A)
r = rank(A,1.e-6)
Many M-files work this way. If no output argument is supplied, the result is
stored in
ans. If the second input argument is not supplied, the function
computes a default value. Within the body o f the function, two quantities
named
nargin and nargout are available that tell you the number of input
4-23
Przeglądanie stron 160
1 2 ... 156 157 158 159 160 161 162 163 164 165 166 ... 239 240

Komentarze do niniejszej Instrukcji

Brak uwag