Mathematica 9 is now available
Student Support Forum
Student Support Forum: 'Trouble with function evaluating too soon' topicStudent Support Forum > General > Archives > "Trouble with function evaluating too soon"

Help | Reply To Topic
Author Comment/Response
Benjamin Blonder
06/26/05 5:09pm

I'm trying for the firs time to write functions in a notebook. I'm trying to plot a variable R, which is defined to depend on some other variables:

R = Epsilon[x]*Theta*Sin[Theta]

is a decent simplified version of it - it depends on multiple variables. When I plot it, I set Theta to be some constant value, and use a range of x. This isn't working however, because of what I think is a problem in my function's definition.

I have

Epsilon[x] := ( some things; last thing = result )

This is fine; no errors. If I then try


I get the correct result, while Epsilon[akjlsdf] (for some undefined variable) returns null. I'd like it instead to stay unevaluated when given a non-declared variable argument, so that I can use it later on in my Plot (this is how things like Sin and Cos work). Right now, my variable R always includes a null, which prevents it from being plotted. I know the issue here is that my function has an If statement which can prevent the function from returning anything, but I think this is alright - it seems like the deeper problem is that the function is already being evaluated at all. How can this be prevented? I'd like to try Epsilon[x] and see Epsilon[x] as the output, rather than the current 'null'. I've attached my notebook to this post. The relevant function is in the first block, while the rest of the notebook is irrelevant, and still full of other issues.


Attachment: SPR.nb, URL: ,
Help | Reply To Topic