]> Creatis software - CreaPhase.git/blob - octave_packages/quaternion-2.0.0/@quaternion/diag.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / quaternion-2.0.0 / @quaternion / diag.m
1 ## Copyright (C) 2010   Lukas F. Reichlin
2 ##
3 ## This program is free software: you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation, either version 3 of the License, or
6 ## (at your option) any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 ## GNU General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {@var{q} =} diag (@var{v})
18 ## @deftypefnx {Function File} {@var{q} =} diag (@var{v}, @var{k})
19 ## Return a diagonal quaternion matrix with quaternion vector V on diagonal K.
20 ## The second argument is optional. If it is positive,
21 ## the vector is placed on the K-th super-diagonal.
22 ## If it is negative, it is placed on the -K-th sub-diagonal.
23 ## The default value of K is 0, and the vector is placed
24 ## on the main diagonal.
25 ## @end deftypefn
26
27 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
28 ## Created: May 2010
29 ## Version: 0.1
30
31 function a = diag (a, b = 0)
32
33   if (nargin == 0 || nargin > 2)
34     print_usage ();
35   endif
36
37   a.w = diag (a.w, b);
38   a.x = diag (a.x, b);
39   a.y = diag (a.y, b);
40   a.z = diag (a.z, b);
41
42 endfunction
43
44
45 %!shared R, S
46 %! Q = quaternion (2, 3, 4, 5);
47 %! R = diag ([Q, Q, Q]);
48 %! W = diag ([2, 2, 2]);
49 %! X = diag ([3, 3, 3]);
50 %! Y = diag ([4, 4, 4]);
51 %! Z = diag ([5, 5, 5]);
52 %! S = quaternion (W, X, Y, Z);
53 %!assert (R == S);