clear all x = 1e8; % try 1e160 > sqrt(realmax) y = 1e8; % try 1e160 > sqrt(realmax) disp('acos') % to be used for |z|>1 % sqrt(1-z*z) = sqrt(1-z)*sqrt(1+z) is useful for VERY large input % (|z| > sqrt(realmax)) for z = [x,-x,1i*y,-1i*y,x+1i*y,x-1i*y,-x+1i*y,-x-1i*y] if (imag(z)==0) z = real(z); % otherwise Matlab takes it complex end if ((isreal(z) && real(z) > 0) || imag(z) < 0) tmp = 1/(z-1i*sqrt(1-z)*sqrt(1+z)); else tmp = z+1i*sqrt(1-z)*sqrt(1+z); end [-1i*log(tmp),acos(z)] end disp('asin') % to be used for |z|>1 % sqrt(1-z*z) = sqrt(1-z)*sqrt(1+z) is useful for VERY large input % (|z| > sqrt(realmax)) for z = [x,-x,1i*y,-1i*y,x+1i*y,x-1i*y,-x+1i*y,-x-1i*y] if (imag(z)==0) z = real(z); end if ((isreal(z) && real(z) > 0) || imag(z) < 0) tmp = 1i*z+sqrt(1-z)*sqrt(1+z); else tmp = -1/(1i*z-sqrt(1-z)*sqrt(1+z)); end [-1i*log(tmp),asin(z)] end disp('acosh') % to be used for z<1 or complex % sqrt(1-z*z) = sqrt(1-z)*sqrt(1+z) is useful for VERY large input % (|z| > sqrt(realmax)) for z = [-x,1i*y,-1i*y,x+1i*y,x-1i*y,-x+1i*y,-x-1i*y] if (imag(z)==0) z = real(z); end tmp = z+sqrt(z-1)*sqrt(z+1); [log(tmp),acosh(z)] end disp('asinh') % to be used for z complex % sqrt(1-z*z) = sqrt(1-z)*sqrt(1+z) is useful for VERY large input % (|z| > sqrt(realmax)) for z = [1i*y,-1i*y,x+1i*y,x-1i*y,-x+1i*y,-x-1i*y] if (imag(z)==0) z = real(z); end if (real(z) > 0 || ((real(z) == 0) && imag(z) >= 0)) tmp = z+sqrt(z-1i)*sqrt(z+1i); else tmp = -1/(z+sqrt(z-1i)*sqrt(z+1i)); % the plus from sqrt(complex) end [log(tmp),asinh(z)] end