# 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,050 questions
Filter by
Sorted by
Tagged with
54 views

### An anonymous function with constraints

I'm not very good at working with anonymous functions, a fact that has now come back to bite me. Suppose I have a function defined as follows: ...
233 views

### How to condition arguments of a pure function?

I would like to exclude the point {x=0,y=0} in the function definition ...
1k views

### How to straighten a curve?

What's the easiest way to get the following animation for a given parabola where the arc length is preserved (that is, for two points in the parabola, I straighten it as follows) My main goal is the ...
47 views

### Defining function with arbitrary length [closed]

I want to make some function with whose input is an arbitrary length of a list. For example, what I did in for explicit case as follow ...
124 views

### What is the usefulness of adding a colon “:” to arguments in the declaration of a function?

I'm studying a code with the following function declaration : FindChain[ x:__ ,y_?FindChainQ,z:__] := { {x},y,{z} } What is the meaning of the colon ":" after the arguments x and z ? What ...
77 views

### Writing a wrapper function computing the memory in use

Is there any way I can write a wrapper that wraps around a piece of code and evaluates how much memory has been used after the execution? Ideally I would like a function that performs the following ...
63 views

### Why does Longest not work on OptionsPattern?

When having a function with optional arguments and options, I frequently find myself writing something like this: ...
91 views

### Find the range of a univariate function over a specific interval of the variable

I would like to find the range of the function below, but only for values of $a$ strictly greater than zero. ...
34 views

### Restrict the domain of a function (and plot) it) when it depends on the value of a parameter

I know similar questions have been asked, but I am very new at Mathematica and other questions/answers are quite complex and do not suit the code I want to write. I want to restrict the domain of the ...
39 views

### A Function of Arguments or a Function of a List of those Arguments – Which is Recommended?

Which is recommended from a programming perspective and has better performance in memory and speed given guaranteed identical output – a function taking many arguments and then referring to those ...
82 views

### Passing Arguments or Passing a List and Referring to its Parts – Which Gives Better Performance?

Which is better for optimizing speed, memory, and coding "safety" – passing arguments to a function or passing a list to the function and call the list's parts? That is, which of the ...
30 views

### Calculate residues at points being rounded (function not rational) [duplicate]

I have a non-rational function $$f(z)=\frac{1}{799. \left(\frac{1}{z}-0.85\right)-798.999 \sqrt{\left(\frac{1}{z}-0.85\right)^2-0.000196}-0.85}$$ and I want to know the residues at its poles. I ...
42 views

### How to Set Text Format by User-Defined Function with Input as String

I have simple but annoying problem here. I guess it occurs to many Mathematica users. The thing is that I wish to define a function to format the text in Mathematica. Yet, I don't know whether it is ...
505 views

### Equivalent Nested Loop Structure (combinations_with_replacement)

Consider the following examples: ...
84 views

### Why some variables get substituted and others don't

I was running into some trouble with my math and I whittled it down to this nugget: ...
106 views

### Alternatives in pure function construction

When I declare a function f in the following form: f[a|b] := 1 then I can use it like: ...
32 views

### Storing a value in array during a for loop

So I have a piece of code below that is used to make a density plot and make the plot into grids, where I then find the center of each grid and store it in the varible called cp. The code for this is ...
59 views

### Apply function modification to curried function

This is based on A function that modifies functions - well-defined operation?, a previous question of mine. Lukas Lang's answer of course works very well, but now I encountered the following edge case:...
2k views

### Nesting multiple functions of multiple variables

I was wondering how one would go about nesting multiple functions of, say, two variables. The problem comes from trying to implement the Chirikov standard map without using "for" cycles. I found a ...
47 views

### FunctionLayer will calculate a distance matrix

I would like, that a FunctionLayer will calculate a distance matrix between two vectors. I try a following approach: ...
43 views

### How to pass results of computations to a function definition?

Here is the following code that works, F[{x_,y_,z_}]:={16(y-x), x(45-z)-y, x*y-4z); x = Array[a,3]; F[x] and the answer is, ...
171 views

### Automating a large operation by making a function

I would like to automate the following operation. To be transparent I shall put my code into separate chunks and explain the process. Suppose I have the following: ...
53 views

### Putting arguments of function automatically

This is a snippet of a code that I have: ...
131 views

### Is there a way to do this more efficiently?

I'm trying to write this Mathematica function to find the optimal price for a model, given some model parameters. This is a stylized example of what I'm trying to do, and I'm wondering what's a better ...
52 views

### RegionPlot Calling User-Defined Function Not Working

This is following up on this post: Function not evaluating as expected I am trying to make a RegionPlot with Manipulate in which ...
42 views

### Function not evaluating as expected [closed]

I'm not sure I understand why this is not working and why it's giving different answers: A simple example illustrating the issue is below: ...
62 views

### How can I pass a list as an index set for product

I want to evaluate a Blaschke product based on the set of zeroes, and compute its preimage for some points. The Blaschke Product looks like: B(z) = z^n\prod_{a_k\in \text{zeroes}} \frac{z - a_k}{1 - ...
43 views

### How to reconstruct a complicated built-in function (e.g. for modification or use in a version that does not have it yet) [duplicate]

Is it possible to extract the definitions for a built-in function to reconstruct a similar user defined function. This would be useful to port new mathematica functionality to older versions or to ...
441 views

### very simple but unexpected aspect of Function[ ]

I've always thought (2#+1)& and Function[x,2x+1] are interchangeable in common sense. But, ...
49 views

### Defining a two-variable function with a parity property

I would like to define a function that has the following property $f(-x,y)=f(x,-y)$. An example is $f(x,y)=x y$. For simple inputs, I can impose this easily enough as: ...
371 views

### Force evaluation of user-defined function

Consider a function that sorts its arguments based on a function called order ...
79 views

### A function that modifies functions - well-defined operation?

Here's my basic setup: Say I have a list of specific symbols and a function noSymbol, which accepts a mathematica expression and checks whether any symbol from my ...
81 views

### how can I modify this function to convert to polar form for any complex expression?

The function from another post is to convert a complex number to polar form. polarForm = Expand[# /. z_?NumericQ :> Abs[z] Exp[I Arg[z]]] & Now if I apply ...
57 views

### How to work symbolically with a compiled function?

I have a compiled function f to be used as a piece of a much larger calculation. I would like to expand out a function that calls ...
2k views

### How can I export my learned ClassiferFunction[] and PredictorFunction[]s?

Mathematica 10 provides beautiful high-level machine learning functionality. Sadly, the learned functions once created are rather opaque objects. I need to use them in other projects, so here is my ...
100 views

### Mathematica ruins domain after explicit summation?

I'm working with this function ...
533 views

### How to generate all possible functions combinations

Assume that I have 3 functions like this (total 10 functions in reality). f1[x_] := 3 x; f2[x_] := x^2 - 1; f3[x_] := 2 x + 5; Now I want to generate all possible ...
90 views

### Why does this DeleteCases not work? [duplicate]

I believe this is simple but I couldn't figure out why this doesn't work. Everything looks good to me. ...
91 views

73 views

### Two “identical” functions returning different values

When taking the norm of a complex number in Mathematica you get the same result when you use the Norm function or the Abs function. So why do the following two functions (kp and kpp) return different ...
52 views

### Construction of Navigation Function: Error

https://en.wikipedia.org/wiki/Navigation_function https://www.sciencedirect.com/science/article/abs/pii/S0921889015302451 https://arxiv.org/pdf/1605.00638.pdf - Paragraph III I am trying to create a ...
So, I'm dealing with iterated polynomials of a single variable—say they're anonymous functions labeled as $p_i$, i.e. p, p,...