# Tagged Questions

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.

214 views

### How to tame the wild MMA?

MMA is a free country. But TOO free sometimes. Just as an example: Clear[a] a[x_] == a[y_] ^:= Round[x] == Round[y] {a[3] == a[3.01], a[3] == a[4]} is {True, ...
56 views

### Memoized function with function parameter [duplicate]

I have some code that takes a function and uses the function to do some complicated computation. Thus, I wish to store this so I don't have to repeat this. Below, it is more simple than my real ...
151 views

### How to find period of a discrete sequence?

For example, {1,2,3,4,5,6,7,8} has period 1, the base is {1} {1,2,4,5,7,8,10,11} has period 3, the base is {1,2} I ...
59 views

### Setting a One Dimensional Function Equal to a Constant over a Specific Range

I am trying to take the output from NDSolve and create a variable equal to the solution except for a certain range of values. Here is the code I am trying to use ...
52 views

100 views

### How to delay the definition of a function from the time of package initialization to when it is first called

I am writing a package where a couple defined functions take a very long time define at initialization time (because they are large CompiledFunctions). However ...
194 views

### How to define functions with a list of arguments

I wante to define several functions, all of them with the same arguments, for example: f[a_, b_, c_]:= ... g[a_, b_, c_]:= ... h[a_, b_, c_]:= ... How can I do ...
368 views

### How to define a periodic function from an interval to Play (monotonic) sound

I would like to define a function on an interval and then duplicate it on other intervals of the same length in order to define a (generally discontinuous) periodic function, from which I could get a (...
130 views

### Programming a MaxMin Linear Optimization

I want to program a function for a two-player game. Basically it's like this: . Each player has an array of options, and the result of the game is based on both players choices. So heres my most ...
188 views

### Name rewriting for Function fails in closure

At its heart, Mathematica is a dynamically scoped language. While the choice of dynamic scope for Mathematica is very much a defensible one, lexical scope is too useful to do without, and Mathematica ...
206 views

### How to define a conditioned function that returns one when x is integer and zero otherwise? [closed]

What is the simplest way to define a conditioned function that returns one when x is integer and zero otherwise? I'm doing it wrong: ...
73 views

### Using functionals in Mathematica [duplicate]

I recently installed Mathematica and I wanted to define a functional in it. This is what I did: ...
436 views

### Skipping “middle” Optional Arguments

Is there a way to call a function where the "middle" arguments should use their default value while specifying values for the "right-most" arguments? For example, given this function: ...
68 views

### Create a function for $\Pi^{-1}(n)$

Is it possible to create a function that gives the inverse of pP[x_] := Sum[PrimePi[x^(1/k)]/k, {k, 1, Floor[Log2[x]]}] i.e., a function that plots ...
51 views

66 views

...
56 views

### Is there a IsDefinedQ function? [duplicate]

I have a function which is a bit expensive to calculate. I want to translate and integrate. I want to translate by values on a grid, store the values of the integral and refine the grid. That is, I ...
68 views

### How can an argument of the form f[t] be injected into the RHS of a function definition [duplicate]

This is what I want, for an arbitrary function x This is what I have done: ...
165 views

### How to specify and use nested options for a function?

I want to write a function that takes options that are nested. For example, suppose the function has one main option, "method" which can take two values, "a" and "b". Also, when method is "a", it can ...
248 views

### Generate the Fibonacci sequence with Accumulate

Is there a way to generate the Fibonacci sequence with the Accumulate function?
122 views

### Force evaluation of the right-hand side of a local variable definition

One can do expression = a + 1; f[a_] := Evaluate[expression] but how would one do something like this ...