Questions tagged [function-construction]

For questions on writing functions (pure or using Set/SetDelayed) for any purpose, including the features that may be incorporated in those functions, such as options, patterns and conditions.

2,415 questions
Filter by
Sorted by
Tagged with
6k 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 ...
• 12.8k
302 views

Difference between function definitions [duplicate]

Possible Duplicate: Functions vs. patterns I thought about describing the context in which I faced this problem, but I figured it is general enough and clear enough to pose it as it is. What ...
• 7,046
20k views

• 949
225 views

Constraining a random function

This question is a follow-up from here. I have a function that generates a list of correlations between some random variables: ...
• 891
1k views

Functional programming and Do loops

I'm writing a Monte Carlo simulation. I'm using a Do loop to create the different simulations, iterating over different ...
• 891
826 views

Is it possible to Clear all variables (but not functions)?

I have written a Mathematica script in which I define functions and variables. Here is a vastly simplified example: ...
• 10.4k
317 views

can a ColorFunction have side effects?

Can anyone explain this (to me) odd behavior. If I run this code once (fresh kernel) it works as intended. ...
• 38.8k
623 views

Using Functions as Arguments to Function

I am trying to make a function like Norm but defined like so: MyNorm[{x_,y_,z_}]=Sqrt[x^2+y^2+z^2]. Mathematica assumes that x, ...
874 views

Generating a position lookup function for an arbitrary list of integers

In my code, I generate a list of integers called numlist. Here is an example numlist: ...
• 10.4k
1 vote
617 views

Piecewise function with a function as argument

I want to define a piecewise function, which has two arguments, one of which is a function of the other's piecewise argument. I am giving an example ...
• 993
1 vote
224 views

How can define a set of nested parameters

I would like to know how I to define a function with a nested set of parameters (or whatever you would like to call it). For example, how would I get the following function ...
• 807
8k views

Variables Inside Functions Not Evaluating

x = 5*y function1[y_] := x function1[5] Am I wrong in thinking that function1[5] should equal 25? Instead this comes out. ...
1 vote
315 views

Calling part of a variable in a user defined function

I have defined a function ...
• 953
245 views

Pack Solve results into a vector

I am currently using a really easy function to get the eigenvectors of a corresponding eigenspace: ...
641 views

Where in the documentation can I find a list of function argument types?

Recently, I learned that it is possible to assign "types" to function arguments in the definition of a function. Suppose I have a function stringFun that does some ...
• 10.4k
488 views

Manipulating OptionsPatterns[]

How do you combine OptionsPatterns? For example, I would like to have a function that can take both options that I specify, and options for all graphs: ...
• 1,571
981 views

Nested definition: How can I define a function with a passed-in expression?

Here's a simplified version of what I'm trying to do: ...
• 19.1k
3k views

Convert an expression to a Function

I need a function which can take an expression and return a pure function based on the symbols in the expression. The symbols might have values so must be protected from evaluation. It is probably ...
• 84.6k