Questions tagged [optional-arguments]

Tag for questions about using optional arguments in Mathematica functions.

109 questions
2
votes
2 answers

How to define a Mathematica Function with varying number of input and output arguments

In Matlab, such issue is handled by varargout, // a cell structure to store all output arguments varargin, // a cell structure to store all input arguments nargout, // number of output arguments nargin // number of input arguments Is there any…
LCFactorization
  • 3,047
  • 24
  • 37
2
votes
1 answer

Force only selected optional arguments

Is there a way to force only selected values for function argument? For example for this function: g[x_, y_, a_: ("b" || "c")] := Print[x, y, a] force a to only get either values "b" or "c".
Tigran
  • 51
  • 2
2
votes
2 answers

Anonymous Function And Optional Arguments

Is there a way to get an optional arguments to work in an anonymous function. Function[{Optional@a},If[a,True,False]]
William
  • 7,595
  • 2
  • 22
  • 70
2
votes
1 answer

Is this the correct method for using optional arguments?

I've read this page but I'm still kind of confused about something. Here's a simple example function, where it simply plots a function. If you give it the ImageSize option, it should use that, but otherwise it should use the default one of…
YungHummmma
  • 3,042
  • 15
  • 30
1
vote
0 answers

Skip middle optional arguments

Is there a way to skip some middle optional arguments? For example for this function: f[{a_: 80, b_: 90}, {c_: 30, d_: 20}] := Print["a=", a, ", b=", b, ", c=", c, ", d=", d] Call something like this: f[{(* empty or some symbols*), 3}, {4,…
Tigran
  • 51
  • 2
0
votes
0 answers

How to pass on optional arguments, but with different default values?

Main question I want to define a function g that calls a function f. g has optional arguments, some of which it passes on to f when f is called. However, I want the default values of the options for gto be different than the defaults f. How do I…