0
$\begingroup$

I wrote a function with three arguments like this

f[a_,b_,c_]:=...

When I call this function MMA requires the input of all three arguments (e.g. f[1,2,3]).

Is there a possibility to define the argument c_ as "varaible" that I can call the function with two (e.g. f[1,2]) or three (e.g. f[1,2,3] arguments?

$\endgroup$
  • 1
    $\begingroup$ See here and note that the lhs of := is really just a pattern and you can have "definitions" for as many patterns as you like. f[1]=2; f[a_,b_]=3; f[x_,y_,z_]:=x $\endgroup$ – Szabolcs Mar 29 '15 at 16:11
  • $\begingroup$ You can also define a default value for c. For example, f[a_, b_, c_:3] := {a, b, c}. Then f[1, 2, 42] gives {1, 2, 42} and f[1, 2] gives {1, 2, 3}. $\endgroup$ – m_goldberg Mar 29 '15 at 16:25