I want to define some function that I can do something for the troubleshooting purpose.
kk[x_, L_] := Module[{x1, x2},
x1 = "x is too big"; x2 = "x is too small" ;
If[L == 1, If[x>1,Print[x1],Print[x2]]];
Print[x];
]
If I plug in L value in the function, then I will get the message. However, if I do not plug in L, then This function will not work because I did not define L.
I want to make this function work no matter there is L or not. So I want to make L optional. Is it possible for me to define such thing in Mathamtica?
kk[x_, L_:1] := . . .to give parameterLthe default value of1. http://reference.wolfram.com/language/tutorial/OptionalAndDefaultArguments.html – Mr.Wizard Aug 22 '16 at 23:49Printis a very limited form of output. Recommend that you use something along the lines ofkk[x_, L_:1] := Module[{x1, x2}, x1 = "x is too big"; x2 = "x is too small"; {If[L == 1, If[x > 1, x1, x2]], x}]then you could usekk[.5] // Column– Bob Hanlon Aug 23 '16 at 00:18