# extra variable in a function

I am trying to give options to a user to enter an advance options to a calculation. Like doing NIntegrate[f,{z,1,4},WorkingPrecision->40] this works without WorkingPrecision and more options. For example

Dummyfunc[f_, g_, din_] := Module[{d,h},

If[din == {}, d = 16, d = din];

h = SetAccuracy[f g, d];

Return[h]];
f = 2/3;
g = 7/6;
test1 = Dummyfunc[f, g];
test2 = Dummyfunc[f, g, 50];


In here I want accuracy default 16 if the user doesn't enter any, but if the user enters it will use that for SetAccuracy.

How can I do that?

Thank you

Update with OptionPattern

Dummyfunc[f_, g_, OptionsPattern[{}]] := Module[{d},

If[OptionValue == {}, d = 16, d = OptionValue];

h = SetAccuracy[f g, d];

Return[h]];
f = 2/3;
g = 7/6;
test1 = Dummyfunc[f, g];
test2 = Dummyfunc[f, g, 50];
Print[test1];
Print[test2];


This also fails.

• If you want your function to have options use OptionsPattern. More on that here reference.wolfram.com/language/ref/OptionsPattern.html Oct 5, 2017 at 9:25
• Thank you but I could not make it work. Using OptionsPattern with no default options. Oct 5, 2017 at 9:38
• Sorry. My bad. The simplest way seems to be to just use the optional argument pattern. Please see my answer below. Oct 5, 2017 at 9:48
• I suggest you read through this tutorial. Oct 5, 2017 at 12:32

Dummyfunc[f_, g_, din_: 16] := Module[{d = din},
h = SetAccuracy[f g, d];
Return[h]];
f = 2/3;
g = 7/6;
test1 = Dummyfunc[f, g];
test2 = Dummyfunc[f, g, 50];
Print[test1];
Print[test2];


(* Outputs *)

0.777777777777778

0.77777777777777777777777777777777777777777777777778

• Thanks it works beautifully. Oct 5, 2017 at 11:13