% solve multiple 3rd degree linear systems at once - no pivoting!
function dg3 = lin_solve_dgr_3(A,b,R)
  nrm =  ...
    + A(1,3,:) .* A(2,2,:) .* A(3,1,:) ...
    - A(1,3,:) .* A(2,1,:) .* A(3,2,:) ...
    + A(1,2,:) .* A(2,1,:) .* A(3,3,:) ...
    - A(1,2,:) .* A(2,3,:) .* A(3,1,:) ...
    + A(1,1,:) .* A(2,3,:) .* A(3,2,:) ...
    - A(1,1,:) .* A(2,2,:) .* A(3,3,:);
  dg3 = zeros(3,R);
  dg3(1,:) = -(...
    +b(3,1,:) .* ( A(1,2,:) .* A(2,3,:) - A(1,3,:) .* A(2,2,:) ) ...
    -b(2,1,:) .* ( A(1,2,:) .* A(3,3,:) - A(1,3,:) .* A(3,2,:) ) ...
    +b(1,1,:) .* ( A(2,2,:) .* A(3,3,:) - A(2,3,:) .* A(3,2,:) ) ...
    ) ./ nrm;
  dg3(2,:) = (...
    +b(3,1,:) .* ( A(1,1,:) .* A(2,3,:) - A(1,3,:) .* A(2,1,:) ) ...
    -b(2,1,:) .* ( A(1,1,:) .* A(3,3,:) - A(1,3,:) .* A(3,1,:) ) ...
    +b(1,1,:) .* ( A(2,1,:) .* A(3,3,:) - A(2,3,:) .* A(3,1,:) ) ...
    ) ./ nrm;
  dg3(3,:) = -(...
    +b(3,1,:) .* ( A(1,1,:) .* A(2,2,:) - A(1,2,:) .* A(2,1,:) ) ...
    -b(2,1,:) .* ( A(1,1,:) .* A(3,2,:) - A(1,2,:) .* A(3,1,:) ) ...
    +b(1,1,:) .* ( A(2,1,:) .* A(3,2,:) - A(2,2,:) .* A(3,1,:) ) ...
    ) ./ nrm;
end