cbrtx.m 385 Bytes
Newer Older
Valentin Platzgummer's avatar
Valentin Platzgummer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
function y = cbrtx(x)
%CBRTX   The real cube root
%
%   CBRTX(x) is the real cube root of x (assuming x is real).  x
%   can be any shape.

  persistent octavep
  if isempty(octavep)
    octavep = exist('OCTAVE_VERSION', 'builtin') ~= 0;
  end
  if octavep
    y = cbrt(x);
  else
    y = abs(x).^(1/3);
    y(x < 0) = -y(x < 0);
    y(x == 0) = x(x == 0);
  end
end