Tag for questions about using optional arguments in Mathematica functions.

learn more… | top users | synonyms

36
votes
6answers
2k views

How can I create a function with optional arguments and options?

Is it possible to create a function with optional arguments that also takes options? Here is a simple example. I have a function f with option "g". It also has ...
13
votes
1answer
564 views

How to Combine Pattern Constraints and Default Values for Function Arguments

EDIT: As several respondents have noted in the answers and comments below, the original example had a default value that would never be used because of the way patterns and default values are ...
20
votes
2answers
524 views

Is there any way to define pure functions with optional arguments?

For example consider the following function: Function[{u,v},u^2+v^4] Is there anyway to define default values for the variables ...
16
votes
4answers
274 views

Can I make a default for an optional argument the value of another argument?

I'd like to define a function with several optional arguments, some of which default to the value supplied for other arguments. For example, I'd like to be able to write something like ...
6
votes
2answers
196 views

Is it possible to use PatternTest and Optional value on one Pattern simultaneously? [duplicate]

Possible Duplicate: How to Combine Pattern Constraints and Default Values for Function Arguments First a simple example: define a function "add" with two arguments, and its second argument ...
12
votes
4answers
318 views

How to make a function with its own options as well as passing options to other functions

I have a function with many of its own options, but I would also like to pass options to subfunctions using the FilterRules function. Here's a simple example: ...
11
votes
1answer
233 views

Is it possible to use Compile on a function with optional arguments?

My Mathematica is a little rusty, so apologies in advance. I think my problem is quite simple, but I can't seem to find the answer on my own! Simple example : ...
9
votes
4answers
201 views

Is it possible to separately call the default value of a variable which isn't at the end of the sequence?

After reading this post I recalled an old question I once met. We know that we can set default values for variables of a function: ...
3
votes
1answer
180 views

Evaluating function only when its optional argument is numeric

I want to have the argument 'a' for myf2 in form of optional argument, but at the same time I need to evaluate the function only if 'a' is Numeric, see also my previous question. ...
7
votes
1answer
136 views

Specifying optional arguments with variables

Perhaps this is poor programming on my part, but I would like to create a function that uses a variable as an optional parameter: var = 2; f[a_:var] := {a} The ...