home *** CD-ROM | disk | FTP | other *** search
- \bigskip
- \bigskip
- {\magonebf 2.4 Real-Valued Vectors (vector)}
-
- An instance of the data type $vector$ is a vector of real variables.
-
- \def\name{$vector$}
- \def\type{$vector$}
-
- \bigskip
- {\bf 1. Creation of a vector }
-
- a) \create v (int\ d)
-
- b) \create v (real\ a,\ real\ b)
-
- c) \create v (real\ a,\ real\ b,\ real\ c)
-
-
- creates an instance $v$ of type $vector$; $v$ is initialized to the zero
- vector of dimension $d$ (variant a), the two-dimensional vector $(a,b)$
- (variant b) or the three-dimensional vector $(a,b,c)$ (variant c).
-
-
- \bigskip
- {\bf 2. Operations on a vector v}
-
- \medskip
- \+\cleartabs & \hskip 2.5truecm & \hskip 5truecm &\cr
- \+\op int dim {}
- {returns the dimension of $v$.}
- \smallskip
- \+\op real length {}
- {returns the Euclidean length of $v$}
- \smallskip
- \+\op real angle {vector\ w}
- { returns the angle between $v$ and $w$.}
- \medskip
- \+\opa real\& {int\ i}
- {returns $i$-th component of $v$.}
- \+\nop {\precond $0\le i \le v$.dim() - 1.}
- \smallskip
- \+\opb vector + {v_1}
- {Addition}
- \+\nop {\precond $v$.dim() = $v_1$.dim().}
- \smallskip
- \+\opb vector - {v_1}
- {Subtraction}
- \+\nop {\precond $v$.dim() = $v_1$.dim().}
- \smallskip
- \+\opb real * {v_1}
- {Scalar multiplication}
- \+\nop {\precond $v$.dim() = $v_1$.dim().}
- \smallskip
- \+\opb vector * {r}
- {Componentwise multiplication with real $r$}
- \medskip
- \+\opb vector\& = {v_1}
- {Assignment, returns $v$}
- \smallskip
- \+\opb bool == {v_1}
- {Test for equality}
- \smallskip
- \+\opb bool != {v_1}
- {Test for inequality}
- \medskip
- \+\ops ostream\& << {O}
- {writes $v$ componentwise to the output stream $O$}
- \smallskip
- \+\ops istream\& >> {I}
- {reads $v$ componentwise from the input stream $I$}
-
- \vfill\eject
-
- \bigskip
- {\bf 3. Implementation }
- \medskip
- Vectors are implemented by arrays of real numbers. All operations on a
- vector $v$ take time $O(v.dim())$, except of dim and $[\ ]$ which take constant
- time. The space requirement is $O(v.dim())$.
-
-