MATLAB FINANCIAL DERIVATIVES TOOLBOX Bedienungsanleitung Seite 71

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 119
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 70
70
d =
1
Comments:
Logical and relational operations.
a
a is 1 because the statement
evaluated is TRUE since
x
x is 2 and greater than 1.
b
b is FALSE
because: “x~=1” returns 1, and “1 & y” returns 0.
c
c is TRUE
because: “x>0” is 1, and “1|y & 1” is “ 1 | 1” which is TRUE.
d
d is
TRUE because: “~y” is 1 and “~x” is 0 so we have “(1 & z | 0==5)
that is equal to “(1 & z | 0) that is equal to: “1 | 0” that is TRUE.
Some examples with matrices and the logical and relational operators follow:
Matlab’s command:
>> clear all; x=[5 0 -1; 2 4 8]; y=[2 1 -1; 1 2 4];
>> a=(x==5), b=(x~=1 & y), c=(2*y==x | ~x), d=(x>0 | y==1 |x~=x)
Matlab’s response:
a =
1 0 0
0 0 0
b =
1 1 1
1 1 1
c =
0 1 0
1 1 1
d =
1 1 0
1 1 1
Comments:
Logical and relational operations with matrices. In
a
a we have only
the first element to be 1 since it the only one that is equal to 5.
We get
b
b to be a TRUE matrix because “x~=1” returns a matrix of
1’s since none element is equal to 1. By definition, all elements in
y
y are taken to be TRUE statements. So TRUE & TRUE gives
b
b full
of 1’s (Figure out how the
c
c and
d
d were evaluated).
4.1.1 The
a
a
n
n
y
y and
a
a
l
l
l
l Functions
Matlab has two build-in functions that are work as logical operators. The first
one is the
a
a
n
n
y
y function that is TRUE if any element of a vector is nonzero.
For vectors,
a
a
n
n
y
y returns 1 if any of the elements of the vector are non-zero.
Otherwise it returns 0. For matrices,
a
a
n
n
y
y operates on the columns of the
Seitenansicht 70
1 2 ... 66 67 68 69 70 71 72 73 74 75 76 ... 118 119

Kommentare zu diesen Handbüchern

Keine Kommentare