From bug-request at octave dot org Tue Nov 15 12:26:46 2005 Subject: Inverse Trigonometric Functions (in degrees) From: "John W. Eaton" To: William Poetra Yoga H Cc: bug at octave dot org Date: Tue, 15 Nov 2005 13:26:39 -0500 On 15-Nov-2005, William Poetra Yoga H wrote: | function retval = acosd (x) | | if (nargin != 1) | usage("acosd (x)"); | end | | x(find(x == inf)) = NaN; | retval = 180./pi.*acos(x); Why is the NaN assignment needed? Doesn't retval = 180/pi*acos(x); do the right thing? | function retval = acotd (x) | | if (nargin != 1) | usage("acotd (x)"); | end | | nz_x = find(x != 0); | retval = ones(size(x)).*90; | retval(nz_x) = 180./pi.*atan(1./x(nz_x)); Instead of these three lines, why not just use retval = 180/pi*acot(x); ? Also, if we do decide that the checks are necessary, it is usually better to write things like x(x != 0) = NaN; instead of x(find (x != 0)) = NaN; and if you are checking for infinity, please use isinf (x) instead of x == inf. Thanks, jwe ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------