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]]];

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?

  • 1
    $\begingroup$ Yes, you can define kk[x_, L_:1] := . . . to give parameter L the default value of 1. reference.wolfram.com/language/tutorial/… $\endgroup$ – Mr.Wizard Aug 22 '16 at 23:49
  • 1
    $\begingroup$ Recommended additional reading, once you have absorbed the tutorial linked above: (4937), (6588), (15718), (1567), (108636) $\endgroup$ – Mr.Wizard Aug 22 '16 at 23:54
  • 1
    $\begingroup$ Print is a very limited form of output. Recommend that you use something along the lines of kk[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 use kk[.5] // Column $\endgroup$ – Bob Hanlon Aug 23 '16 at 0:18