View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tim Williams Tim Williams is offline
external usenet poster
 
Posts: 1,588
Default How to indicate that UDF didn't converge?

Is the result of the function being used in other formulae?

You could always just return "Not converged!" (or other appropriate message)
and have any downstream formulas only handle a numeric return value.
Add some conditional formatting to the cells to highlight non-numeric
results.

Tim.

--
Tim Williams
Palo Alto, CA


"MrShorty" wrote in
message ...

I have a handful of UDF's that use iterative algorithms to numerically
arrive at a solution (usually either a Newton-Raphson type algorithm or
successive approximations). I like to put a check on the number of
iterations, to prevent getting stuck in an infinite loop should the
problem diverge. Generic function looks something like:

function myudf(arglist, optional init)
if ismissing(init) then init= some reasonable initial guess for generic
problems of this sort
code setting up initial values for the iteration
it=0
do
it=it+1
iteration code to find next value from old value
loop until convergeance criteria or it=100
myudf=result
end function

What I would like to add is something to let me know when the
convergeance criteria hasn't been met, but rather the function has
ended because we've reached the maximum number of iterations. I'm just
looking for ideas. How would you inform me that the function reached
maxiterations without converging? message box? have the function
return an error? other possibility?

Thanks in advance.


--
MrShorty
------------------------------------------------------------------------
MrShorty's Profile:

http://www.excelforum.com/member.php...o&userid=22181
View this thread: http://www.excelforum.com/showthread...hreadid=495594