1 | function r = rdivide(a, b) |
---|
2 | % ./ Right array divide. |
---|
3 | % (Quaternion overloading of standard Matlab function.) |
---|
4 | |
---|
5 | % Copyright © 2005, 2006 Stephen J. Sangwine and Nicolas Le Bihan. |
---|
6 | % See the file : Copyright.m for further details. |
---|
7 | |
---|
8 | error(nargchk(2, 2, nargin)), error(nargoutchk(0, 1, nargout)) |
---|
9 | |
---|
10 | % There are three cases to be handled: |
---|
11 | % |
---|
12 | % 1. Left and right arguments are quaternions. |
---|
13 | % 2. The left argument is a quaternion, the right is not. |
---|
14 | % 3. The right argument is a quaternion, the left is not. |
---|
15 | % |
---|
16 | % In fact, cases 1 and 3 can be handled by the same code. Case 2 |
---|
17 | % requires different handling. |
---|
18 | |
---|
19 | if isa(b, 'quaternion') |
---|
20 | |
---|
21 | % The right argument is a quaternion. We can handle this case by |
---|
22 | % forming its elementwise inverse and then multiplying. Of course, |
---|
23 | % if any elements have zero norm, this will result in NaNs. |
---|
24 | |
---|
25 | r = a .* b .^ -1; % Changed 24/2/2006 to use .^ -1 instead of inv. |
---|
26 | |
---|
27 | else |
---|
28 | |
---|
29 | % The right argument is not a quaternion. We assume therefore |
---|
30 | % that if we divide components of the left argument by the right |
---|
31 | % argument, that Matlab will do the rest. Obviously if the right |
---|
32 | % argument is zero, there will be a divide by zero error. |
---|
33 | |
---|
34 | if ispure(a) |
---|
35 | r = quaternion( x(a) ./ b, y(a) ./ b, z(a) ./ b); |
---|
36 | else |
---|
37 | r = quaternion(s(a) ./ b, x(a) ./ b, y(a) ./ b, z(a) ./ b); |
---|
38 | end |
---|
39 | end |
---|