# v_qrdotdiv

## PURPOSE

V_QRDOTDIV divides two real quaternions arrays elementwise q=[x,y]

## SYNOPSIS

function q=v_qrdotdiv(x,y)

## DESCRIPTION

    V_QRDOTDIV divides two real quaternions arrays elementwise q=[x,y]

     Inputs:  x(4n,...)
              y(4n,...)   Two real quaternion arrays of equal size

     Outputs: q(4n,...)    The Hadamard quaotient (i.e. ./) of the input arrays
                           If y is omitted then q = x^(-1)

          Copyright (C) Mike Brookes 2000-2012
          Version: $Id: v_qrdotdiv.m 10865 2018-09-21 17:22:45Z dmb $

       VOICEBOX is a MATLAB toolbox for speech processing.
       Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       This program is free software; you can redistribute it and/or modify
       it under the terms of the GNU Lesser General Public License as published by
       the Free Software Foundation; either version 3 of the License, or
       (at your option) any later version.

       This program is distributed in the hope that it will be useful,
       but WITHOUT ANY WARRANTY; without even the implied warranty of
       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       GNU Lesser General Public License for more details.

       You can obtain a copy of the GNU Lesser General Public License from
       https://www.gnu.org/licenses/ .

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

## SOURCE CODE

    0001 function q=v_qrdotdiv(x,y)
    0002 %V_QRDOTDIV divides two real quaternions arrays elementwise q=[x,y]
    0003 %
    0004 % Inputs:  x(4n,...)
    0005 %          y(4n,...)   Two real quaternion arrays of equal size
    0006 %
    0007 % Outputs: q(4n,...)    The Hadamard quaotient (i.e. ./) of the input arrays
    0008 %                       If y is omitted then q = x^(-1)
    0009 %
    0010 %      Copyright (C) Mike Brookes 2000-2012
    0011 %      Version: $Id: v_qrdotdiv.m 10865 2018-09-21 17:22:45Z dmb $
    0012 %
    0013 %   VOICEBOX is a MATLAB toolbox for speech processing.
    0014 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
    0015 %
    0016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0017 %   This program is free software; you can redistribute it and/or modify
    0018 %   it under the terms of the GNU Lesser General Public License as published by
    0019 %   the Free Software Foundation; either version 3 of the License, or
    0020 %   (at your option) any later version.
    0021 %
    0022 %   This program is distributed in the hope that it will be useful,
    0023 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
    0024 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0025 %   GNU Lesser General Public License for more details.
    0026 %
    0027 %   You can obtain a copy of the GNU Lesser General Public License from
    0028 %   https://www.gnu.org/licenses/ .
    0029 %
    0030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0031 persistent a b c
    0032 if isempty(a)
    0033     a=[1 2 3 4 2 1 4 3 3 4 1 2 4 3 2 1];
    0034     b=[1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4];
    0035     c=[6 8 10 11 15 16];
    0036 end
    0037 s=size(x);
    0038 x=reshape(x,4,[]);
    0039 if nargin<2 % one argument - just invert x
    0040     m=sum(x.^2,1);
    0041     x=x./m(ones(4,1),:);
    0042     x(2:4,:)=-x(2:4,:);
    0043     q=reshape(x,s);
    0044 else  % multiply by conjugate of y and then divide by |y|^2
    0045     y=reshape(y,4,[]);
    0046     m=sum(y.^2,1);
    0047     q=x(a,:).*y(b,:);
    0048     q(c,:)=-q(c,:);
    0049     q=reshape(sum(reshape(q,4,[]),1),s)./m(ones(4,1),:);;
    0050 end