~ubuntu-branches/ubuntu/utopic/octave-quaternion/utopic

« back to all changes in this revision

Viewing changes to inst/@quaternion/inv.m

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot, Rafael Laboissiere
  • Date: 2013-05-20 13:44:12 UTC
  • mfrom: (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130520134412-48om2w3toyjytax8
Tags: 2.0.2-2
[ Rafael Laboissiere ]
debian/copyright: Use the octave-maintainers mailing list as upstream
contact

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
## Copyright (C) 2010, 2011   Lukas F. Reichlin
 
1
## Copyright (C) 2010, 2011, 2012   Lukas F. Reichlin
2
2
##
3
3
## This program is free software: you can redistribute it and/or modify
4
4
## it under the terms of the GNU General Public License as published by
20
20
 
21
21
## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
22
22
## Created: May 2010
23
 
## Version: 0.2
 
23
## Version: 0.3
24
24
 
25
25
function a = inv (a)
26
26
 
34
34
    a.x = -a.x / norm2;
35
35
    a.y = -a.y / norm2;
36
36
    a.z = -a.z / norm2;
 
37
  elseif (issquare (a.w))
 
38
    ## blockwise inversion, use recursion
 
39
    ## the formula is well-known from linear algebra
 
40
    n = rows (a);       # a is square
 
41
    m1 = fix (n/2);
 
42
    m2 = m1 + 1;
 
43
 
 
44
    A = subsref (a, substruct ("()", {1:m1, 1:m1}));
 
45
    B = subsref (a, substruct ("()", {1:m1, m2:n}));
 
46
    C = subsref (a, substruct ("()", {m2:n, 1:m1}));
 
47
    D = subsref (a, substruct ("()", {m2:n, m2:n}));
 
48
 
 
49
    iA = inv (A);
 
50
    iAB = iA * B;
 
51
    CiA = C * iA;
 
52
    X = inv (D - C * iAB);
 
53
    Y = X * CiA;
 
54
    
 
55
    a = [iA + iAB*Y, -iAB*X;
 
56
                 -Y,      X];
37
57
  else
38
 
    ## TODO: quaternion arrays
39
 
    error ("quaternion: inv: implemented for scalar quaternions only");
 
58
    error ("quaternion: inv: require square matrices of quaternions");
40
59
  endif
41
60
 
42
61
endfunction