octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch for erfinv.m


From: Alois Schloegl
Subject: Patch for erfinv.m
Date: Mon, 21 Jan 2008 12:15:52 +0100
User-agent: Icedove 1.5.0.14pre (X11/20071018)

Consider the following patch for erfinv.

It (1) replaces z_old and z_new by a single variable z, and
(2) makes the initial checks simpler.

The code becomes leaner, and a bit faster.


Alois


===================================================================
RCS file: /cvs/octave/scripts/specfun/erfinv.m,v
retrieving revision 1.22
diff -r1.22 erfinv.m
2a3
> ##               2008 Alois Schloegl
47,56c48,50
<   i = find ((x < -1) | (x > 1) | isnan(x));
<   if any (i)
<     y(i) = NaN * ones (length (i), 1);
<   endif
<
<   t = find (x == -1);
<   y (t) = (-Inf) * ones (size (t));
<
<   t = find (x == 1);
<   y (t) = Inf * ones (size (t));
---
>   y(~(abs(x) < 1)) = NaN;  %% x<1, x>1, x=NaN
>   y(x == -1) = -Inf;
>   y(x == +1) = +Inf;
61,65c55,57
<     z_old = ones (length (i), 1);
<     z_new = sqrt (-log (1 - abs (x(i)))) .* sign (x(i));
<     while (any (abs (erf (z_new) - x(i)) > tol * abs (x(i))))
<       z_old = z_new;
<       z_new = z_old - (erf (z_old) - x(i)) .* exp (z_old.^2) * s;
---
>     z = sqrt (-log (1 - abs (x(i)))) .* sign (x(i));
>     while (any (abs (erf (z) - x(i)) > tol * abs (x(i))))
>       z = z - (erf (z) - x(i)) .* exp (z.^2) * s;
71c63
<     y(i) = z_new;
---
>     y(i) = z;
===================================================================


--
 Dr. Alois Schloegl
 Intelligent Data Analysis Group (IDA)
 Fraunhofer-Institut fuer Rechnerarchitektur und Softwaretechnik, FIRST
 Kekulestrasse 7
 12489 Berlin, Germany



reply via email to

[Prev in Thread] Current Thread [Next in Thread]