MATLAB FINANCIAL DERIVATIVES TOOLBOX Uživatelský manuál Strana 69

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 119
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 68
68
Fourth Section
4. Control Flow
A collection of commands that include repetition of a conditional code
segment is termed as control flow structure. In Matlab as in any
programming language, control flow commands are presented via the
execution of a conditional expression (e.g. execute a code segment if a
statement is true) that is based on logical and/or relational operators.
4.1. Logical and Relational Operators
To evaluate a conditional code, it is needed to have a Boolean expression
that takes two possible values: TRUE or FALSE. Matlab defines a TRUE
statement with the value of 1 and a FALSE with the value of 0. In Matlab
there are six relational operators: “<” (less than), “<=” (less than or equal to),
“>” (greater than), “>=” (greater than or equal to), “==” (equal to), and “~=”
(not equal to). These can be used to compare a variable to a scalar, a vector
to a vector or a multidimensional array to another one. Always the
comparisons are done element by element and the result is a
scalar/vector/matrix of the same size as then ones originally used, with
elements set to one where the relation is true and elements set to zero where
it is not.
In addition, Matlab has (at least) 3 logical operators: “&” (logical AND), “|”
(logical OR), and “~” {logical complement - not). If we have two matrices “A”
and “B” that share the same dimensionality then:
“A” & “B” is a matrix whose elements are 1's where both “A” and “B”
have non-zero elements, and 0's where either has a zero element. “A”
and “B” must have the same dimensions (or one can be a scalar). For
example in the case of scalars: 1 & 0, 0 & 1 and 0 & 0 will result to 0
(FALSE) while 1 & 1 is 1 (TRUE).
“A” | “B” is a matrix whose elements are 1's where both “A” or “B” has
a non-zero element and 0's where both have zero elements. “A” and
“B” must have the same dimensions (or one can be a scalar). For
Zobrazit stránku 68
1 2 ... 64 65 66 67 68 69 70 71 72 73 74 ... 118 119

Komentáře k této Příručce

Žádné komentáře