Skip to content
Prev 245573 / 398506 Next

how to see what's wrong with a self written function?

Here is what I get when I have:

options(error=utils::recover)

I always run with the option so that on an error, I get dumped in the
browser to see what is happening.  It appears that 'i == 3' when the
error occurs and you can also see the values of 'x':
+        x=c()
+        x[1]=x1
+        i=1
+        while ( f(x[i])!=0 ) {
+                i=i+1
+                if (i==2) {
+                        x[2]=x[1]-f(x[1])*(x[1]-x0)/(f(x[1])-f(x0))
+                } else {
+
x[i]=x[i-1]-f(x[i-1])*(x[i-1]-x[i-2])/(f(x[i-1])-f(x[i-2]))
+                }
+        }
+        x[i]
+ }
[1] 2.978429
Error in while (f(x[i]) != 0) { : missing value where TRUE/FALSE needed
In addition: Warning message:
In log(x) : NaNs produced

Enter a frame number, or 0 to exit

1: regulafalsi(function(x) x^(1/2) + 3 * log(x) - 5, 1, 100)

Selection: 1
Called from: top level
Browse[1]> i
[1] 3
Browse[1]> x
[1] 100.00000  18.35661 -42.22301
Browse[1]>
On Tue, Dec 21, 2010 at 2:39 PM, casperyc <casperyc at hotmail.co.uk> wrote: