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

### Can't get differential root to plot. What am I doing wrong?

I've been trying to solve a complicated system of differential equations. After some simplifying, I've executed the following and get a DifferentialRoot as output, but for some reason, I can't get it ...
1 vote
90 views

### Evaluating step functions [closed]

Please guys, how do I tell Mathematica to return f(a-b)= 1 if a=b and 0 otherwise? This means that f(0)=1 and f(x)=0 for x>0.
• 31
61 views

### Issue solving a recurrence relation

I´m trying to solve the following recurrence relation in Mathematica: ...
• 145
143 views

### Finding and Plotting Minima

Using the same concept discussed in Plotting minima of a mutivariable function, I am trying to plot the minimas for the function z[v_, t_] here. This is what I am ...
• 149
41 views

### Issue solving recurrence relation

I´m trying to solve the following recurrence relation: ...
• 145
280 views

### How can I sort all levels except the innermost level?

How can I sort all levels except the innermost level? The number of levels is unknown. For example: list = {{{d, c}, {b, a}}, {{4, 3}, {2, 1}}} If we needed to ...
• 785
229 views

### How to optimize performance with DeleteDuplicates?

Does anyone know how to improve this for speed performance? The code works fine, but DeleteDuplicates makes it really slow for large lists. ...
• 785
1 vote
47 views

### Selecting only the quartic terms from an expression

I am trying to create a function that returns a list with every quartic term (in total, meaning that \[CapitalPhi]1^2 * \[CapitalPhi]2 ^2 would count). what I have ...
• 13
1 vote
73 views

### How to exclude singularities for NMinimize

I have an messy expression and want to apply NMinimize to it, have no idea how to force NMinimize to ignore the singularities it ...
• 336
263 views

### How can I permute pair of elements in a list?

How can I find all permutations (ways of exchanging positions of pairs in brackets) in a list? The position of elements not in pair should not change. ...
• 785
173 views

### How to replace sequences in a list based on specific patterns?

I have this list: list = {V1, A1, B1, A2, B2, B1 A1, V2} I want to replace sequences like A1, B1 with ...
• 785
175 views

### How can I find all equivalent swapping of some edges in a graph?

This is related to electrical networks, so let me explain a bit about it first. Assume that I have a branch or a loop consisting of only voltage sources in series, as shown below. We know that if we ...
• 785
45 views

### Create custom Code like Cell

I like the formatting for Code and would like to use it for all my input. However, I want to be able to have both Initialization and non-initialization cells and I'...
• 4,591
1 vote
69 views

### Problem defining Function inside Module to verify ODE solution [duplicate]

I modified the question. It turns out this problem has nothing to do with using a package. New style or standard style./ Same problem shows in a normal module in notebook. This is the most bizzar ...
• 148k
51 views

### DeleteDuplicates By Proportionality

I have a list of expressions and I would like to delete "duplicates" that are proportional to each other where the (simplified) proportionality constant satisfies NumericQ. What would be the ...
• 4,591
68 views

### Why does the gather not seem to work?

Why isn't {4, 6} include in the first group? I expected the result would be {{{1, 9}, {2, 3}, {4, 6},{5, 10}}, {{11, 15}}} ...
• 785
69 views

### Implementing a permutation in Mathematica

The context of this question is to calculate DiracTrace in dimensional regularization, using a Scheme. The procedure is implemented in FeynCalc, but I want to implement explicitly. Let's consider a ...
• 377
153 views

### Specifying properties of a function as assumptions

I am trying to simplify expressions involving a function $f: \mathbb C \to \mathbb C$ which satisfies $$f(-z) = -f(z), \quad f(z^*) = f(z)^*, \quad \forall z \in \mathbb C.$$ I do not want to specify ...
• 143
1 vote
61 views

### How can I efficiently gather similar lists?

I want to gather similar lists by the function sameQ below. Gather works well here, but it's too slow for large data. My real <...
• 785
21 views

### How to define function in a better way and how to ensure the result of NIntegrate is correct?

I just begin to use mma this year, but i only know little about it. Could any one guide me plz. ...
34 views

### ReplaceIndexed function

I would like a replaceAllIndexed in the spirit of MapIndexed where there is an easy way to access the counter in the rule. I ...
• 4,591
164 views

### How to retrieve the index of a subset in Subsets[list,nspec,{s}]?

Subsets[Range[2000], {4}, {n}] would give the $s^{th}$ subset of the Subsets[Range[2000], {4}]. For example, ...
• 785
102 views

### Function Definition without Arguments

I need a simple function that can be called without any arguments, myFunction[ ], that will create an element of a data structure. However, each element in the data structure has a "label" ...
109 views

### How to insert a graphics between two points?

How can I insert the resistor between points {1,1} and {2,1} without modifying res (zoom is ...
• 785
1k views

### Why doesn't b = a; f[a_] := b; f[2] return 2?

As the title asks, why does b = a; f[a_] := b; f[2] evaluate to a rather than 2?
• 67.5k
140 views

### Catch error propagation

I'd like my function to work only for arrays with all positive members, eg: myf[arr_] := Reverse@arr /; AllTrue[arr, Positive]; So ...
• 1,894
68 views

### How to implement this zip function? zip[g,{f[{a,b}],f[{c,d}]}] to f[{g[{a,c}],g[{b,d}]}]

I have a function that returns an expression in the form f[{a,b}], and I use this function twice and assemble the expression ...
63 views

### Why does this FirstPosition not work? [closed]

Why does this return {0} which is incorrect? I understand that I can use the pattern StringQ but I want to use not a number here. ...
• 785
76 views

### Using Function for Contours

Is this a bug in Contours or I am using the function incorrectly? In the second code the function works well but in the third code it fails. The first and third ...
• 20.2k
38 views

### Writing list as disjoint union of input lists

Suppose I have two lists, s1={{1,2,3},{3,1,2},{3,1,2},{2,3,1},{3,2,1},{1,3,2}} and ...
• 101
1 vote
32 views

### TensorProduct in a FunctionLayer cannot compile correctly

My network can output an array of 6x512x512 size at the end, now I want to multiply an array of length 3 for each of these 6 channels to get the color of the different channels, I am using the ...
71 views

### How to use || as a function name and apply it to calculate the equivalent resistance of parallel resistors as we typically write?

The equivalent resistance $R_{eq}$ of $n$ resistors in parallel can be calculated from this: Would it be possible to define a function to calculate the equivalent resistance of resistors with the ...
• 785
23 views

### Keep list of user-definitions

Is there some easy way to keep track of user defined definitions. Or perhaps even better definitions made while some definitionRecordingFlag==True. This is prompted ...
• 4,591
270 views

### How can I find all the different ways to group integer numbers from 1 to 10 into 3 lists?

(Unfortunately, I couldn't change the bounty message. By n above I meant the number of sublists.) How can I group a list of integers from 1 to 10 into 3 sublists of ...
• 785
93 views

### Problem compiling derivative of expression

I need to compile functions for an expression and its derivative and then pass these on to a precompiled worker loop for further processing. An If statment detects when the expression parameter expr ...
• 101
249 views

123 views

### How to obtain all definitions in which a symbol appears?

My question is very similar to https://stackoverflow.com/questions/5840313/how-to-get-all-definitions-associated-with-other-symbols except I am looking to find all definitions in which a symbol ...
• 4,591
406 views

### How to stop mapping on true results for large lists?

Assuming I have a long list (real data with more than 100k elements). I have a function that I want to apply to the list, for example, EvenQ. I want the mapping to stop once the result for one element ...
• 785