Tag for questions about using optional arguments in Mathematica functions.

learn more… | top users | synonyms

40
votes
6answers
3k 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 ...
21
votes
2answers
756 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 ...
20
votes
5answers
488 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 ...
15
votes
1answer
845 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 ...
13
votes
4answers
491 views

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

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: ...
13
votes
1answer
112 views

Unexpected pattern matching behaviour: PatternSequence vs. Optional

fixed in 10.1 (windows) Consider the following pattern-matching expressions: ...
11
votes
2answers
196 views

How do I override options with my own defaults?

I'm calling a function f from within a function g and would like to pass any valid options for ...
11
votes
1answer
279 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 : ...
10
votes
4answers
239 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: ...
10
votes
2answers
512 views

How to test if optional argument has been given?

I understand that the last call (f[1]) returns True because arg does not exist and thus ...
7
votes
1answer
160 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 ...
7
votes
2answers
143 views

Change some option of a function when calling it [duplicate]

Say I have defined some function like f[p_] := Plot[Sin[p*x], {x, 0, 2 Pi}] Now in most cases, I just need to specify the value of ...
6
votes
2answers
225 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 ...
6
votes
3answers
156 views

How to speed up the plotting of B-spline curve?

Three months ago, I asked a quesion about B-Spline basis function here, Today, I used this function to plot B-spline curve. The definition of $N_{i,p}$ ...
6
votes
1answer
132 views

How to find the options available for a function? [duplicate]

I was trying to create an animated .gif with Mathematica. I knew that the function to use was Export["animation.gif",tableplot] where ...
6
votes
1answer
111 views

A question about two ways to use Default

Usually we define a function with default values by the syntax x_:default, but there is another technique to do this by registering a global default value with ...
4
votes
2answers
174 views

How to use Optional as an omissible parameter in pattern-match?

Below is a function intended to test if an expression is a polynomial in which all the coefficients and exponents are integers: ...
4
votes
2answers
114 views

How do I make my function behave more like Plot? [duplicate]

I have written a function Fun as below: ...
4
votes
1answer
91 views

Add options to upvalues

I have some objects that I want to present in TeXForm. Thus, it is easily to do as follows: YoungTableau/:TeXForm[YoungTableau[diagram_]] However, what if I ...
3
votes
3answers
312 views

Plot graphs with direction and numbered in Mathematica

I would like to write a code in Mathematica such that it shows the direction with numbers on points. I wrote this code which does not do this. I want just to complete this code with two options I ...
3
votes
1answer
409 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. ...
3
votes
1answer
70 views

Function of arguments given in non-fixed order [duplicate]

normally we define functions as f[x_, y_, z_] := ArcSin[x^2*y/z] however when one has many arguments (as I do) I find difficult to remember what is the meaning ...
2
votes
1answer
51 views

Is there a shorthand for Optional with Condition?

I have a recursive function that does some work to an object for a repeatedamount of times. ...
2
votes
1answer
116 views

How can I define a function taking two distinguishable sets of options?

It commonly happens that one wants to define some function foo which in turn calls some other function (e.g., Plot) that can ...
2
votes
1answer
86 views

How to specify optional arguments that take functional values

I am trying to make a function with an optional argument that may change but mathematica caches the value when the function is defined. Here is an example where the optional time variable is set when ...
2
votes
0answers
92 views

How can this function's options be used in different places? [duplicate]

I wrote this function to make a ListPlot where the points are colored by a third argument. ...
1
vote
1answer
650 views

Which methods are available for NMinimize? [closed]

I can't find in the documentation the list of methods available to NMinimize[]. Is there a way to get this? The NMinimize page in Documentation Center mentions only ...
1
vote
1answer
96 views

How to deal with the condition that a function own many options?

Assming that I have a function myFunc which has some options. ...
1
vote
0answers
36 views

Optional arguments with lists as function parameter

I'm developing a function to process 3D data volumes which is very similar to ImageTake and should support the same optional arguments. ...
0
votes
3answers
153 views

How to combine multiple functions into a single function, indexed bya new argument

I have a system of expressions (matrices) which correspond to increasing orders of precision in a theory. These expressions are quite complex (require about 40+ lines of code to produce) and are not ...
0
votes
2answers
862 views
0
votes
0answers
24 views

How do I call a function that has a default parameter value? [on hold]

I have defined a function that has a default value for one of it's parameters. ...
0
votes
0answers
31 views

Use Map with OptionValue [duplicate]

Trying to map OptionValue to a list of option names doesn't work. ...
0
votes
1answer
111 views

How to make an index optional?

Can I define a relation between variables, such that the expression will also be evaluated (then assuming all indices are equal) when no index is given? $$ x_i + y_j = \delta_{ij} ...