# Mathematica crashes after evaluating a call to a user-defined function [closed]

I have recently installed Mathematica 9 on my macbook pro, os version 10.6.8. As you can see in the minimal example notebook you can download here:

https://dl.dropbox.com/u/1163801/crashing_notebook.nb

when I simply run a sequence of inputs everything is fine, bit as soon as I put exactly the same inputs into a function of two variables and call this function with the same parameters used before the UI crashes. This doesn't happen for all functions, but for this one it does. Any ideas?

Any help would be very much appreciated.

PS: Don't ask why I define a constant to be a function of S, this will be used as a function of S later.

-

## closed as too localized by rcollyer, whuber, Sjoerd C. de Vries, belisarius, ArtesJan 16 '13 at 21:18

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

You're using N as a variable in the function definition. It is highly recommended that you don't start your symbol names with a capital letter to avoid these conflicts, and care must be taken if you choose to ignore the recommendation. It is especially important when you are only using a single letter. –  rcollyer Jan 16 '13 at 15:55
Consider f[x_, N_] := N[x, N]. With this definition, f[Pi, 20] evaluates to 20[π, 20]. Not what you would want, is it? Your code does something like that. –  m_goldberg Jan 16 '13 at 16:47
@Nasser In fact in this example N is coloured green in the function, which can be a warning sign. –  Szabolcs Jan 16 '13 at 18:29

To expand on the comment by @rcollyer, that is exactly the source of trouble here. You have effectively disabled the numeric evaluation. The table of symbolic results gets huge quickly. As an experiment (to be done with caution) remove the N[] wrappers from the Erf evaluations. Then do

res = makeFirstCrossing[1, 25];


(And make good and well sure you use that semicolon.)

The result has a LeafCount of 586830445. I've no doubt that you are simply running out of memory.

If you change the pattern variable from N_ to n_ and likewise change the two usages at the beginning of the function then it will behave itself.

-
Thank you! Problem solved. (Though I am a little angry at myself for not seeing that...) –  Joschka Beyer Jan 16 '13 at 17:23
+1, for the quote "And make good and well sure you use that semicolon." alone! –  rcollyer Jan 16 '13 at 17:59