Skip to main content

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.

Filter by
Sorted by
Tagged with
1 vote
0 answers
53 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 <...
internet's user avatar
  • 793
0 votes
0 answers
17 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. ...
Middle's user avatar
  • 1
0 votes
0 answers
31 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 ...
Kvothe's user avatar
  • 4,491
2 votes
2 answers
65 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, ...
internet's user avatar
  • 793
0 votes
3 answers
91 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" ...
ZGurdal's user avatar
5 votes
1 answer
101 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 ...
internet's user avatar
  • 793
7 votes
3 answers
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?
xzczd's user avatar
  • 66.8k
2 votes
2 answers
136 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 ...
lesobrod's user avatar
  • 1,699
2 votes
2 answers
62 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 ...
Tapiocaweasel's user avatar
2 votes
1 answer
58 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. ...
internet's user avatar
  • 793
3 votes
1 answer
73 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 ...
azerbajdzan's user avatar
  • 18.7k
0 votes
0 answers
35 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 ...
Tanatofobico's user avatar
1 vote
0 answers
30 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 ...
Schwarzer's user avatar
2 votes
1 answer
66 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 ...
internet's user avatar
  • 793
0 votes
0 answers
22 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 ...
Kvothe's user avatar
  • 4,491
1 vote
6 answers
260 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 ...
internet's user avatar
  • 793
3 votes
2 answers
88 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 ...
Mikl's user avatar
  • 101
4 votes
2 answers
246 views

Can Mathematica return the closed forms of 'arbitrary' function compositions?

I have only just downloaded Mathematica, so I am entirely new to this software. Here is what I am trying to do: If $f(x) = \frac{x}{2}$ is an example function, and $f^{(n)}(x)$ is the composition of $...
Wisdom Iwueze's user avatar
4 votes
2 answers
195 views

Reverse association and map through its values/keys

I suspect this could be done in a shorter and more readable code: Challenge: do it without Normal and Association. ...
azerbajdzan's user avatar
  • 18.7k
0 votes
1 answer
61 views

Generate all commutators and anti-commutators up to a certain order of a list of matrices

I am given a list of matrices. At first order I want to evaluate the commutators and anti-commutators of all pairs in the list and return a new list that contains two lists: one containing all ...
JohnnyB's user avatar
  • 95
4 votes
2 answers
236 views

Given two functions, generate all nested applications of the functions to a given order

I have two functions $f$ and $g$. Given some order parameter $n$, I want to created all nested applications of $f$ and $g$ and save them in a list. For example, for order 1 we will have ...
JohnnyB's user avatar
  • 95
4 votes
1 answer
79 views

PatternTest in Function

This is probably trivial and already asked but I did not find it. How to use PatternTest inside Function (...
azerbajdzan's user avatar
  • 18.7k
2 votes
1 answer
69 views

Expression as parameter to function that evaluates it, best way to do it?

I need a function fSum that computes the angular sum for some expression, like this: fSum[3 Sin[2 x], 0, 2 π] Or from a predefined function, like this: f[x] = 2 Sin[3 x]; fSum[f, 0, 2 π] Or plots it ...
Mikl's user avatar
  • 101
0 votes
2 answers
61 views

Problem with $ sign in temporary function parameter

I am having a problem with $ sign in the name of a parameter to a temporary function. The functions I have should compute the angular sum (or turning angle) for some expression generated by function <...
Mikl's user avatar
  • 101
7 votes
6 answers
465 views

Applying several functions to the same argument

Is there a more concise way of achieving the following result (possibly without d |->)? ...
azerbajdzan's user avatar
  • 18.7k
4 votes
1 answer
103 views

Functions, Speed, and Evaluate[]

This is a question about how Mathematica works, rather than how to solve a specific instance of an issue, so apologies in advance if this isn't admissible for this StackExchange. I've noticed some ...
ScienceSnake's user avatar
9 votes
5 answers
840 views

Create n random points on [0,1] with minimum distance

Given a positive integer n and a small positive real number s. How to create distribution for ...
imida k's user avatar
  • 4,295
0 votes
0 answers
52 views

How to generate non-duplicate list of tuples with integer elements {-2, 0, 2}?

How can I generate all possible non-duplicate eighttupleList where each element, $a_i$, can be an integer from the set {-2, 0, 2}? ...
emnha's user avatar
  • 2,111
2 votes
0 answers
78 views

How to define the square root of an operator [duplicate]

How can I define the operator $\sqrt{m^2-\frac{\partial^2}{\partial x^2}}$, such that it acts on the function $\psi(x)$ as follows: \begin{eqnarray*} \sqrt{m^2-\frac{\partial^2}{\partial x^2}}\...
Yu-Sen Zhou's user avatar
6 votes
1 answer
119 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 ...
Kvothe's user avatar
  • 4,491
5 votes
5 answers
400 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 ...
internet's user avatar
  • 793
4 votes
3 answers
237 views

Converting to a scalar pure function without getting the warning messages

I am using this from the function repository for which I need to convert one of my functions into a unique form. A simple example is like this: Suppose I have, ...
codebpr's user avatar
  • 2,253
1 vote
0 answers
59 views

Assign a function to other function with the change of the variable

I want to define a function that contains other functions but with other variables. Is it possible? For example, I would like to do something like this: ...
blahblah's user avatar
1 vote
2 answers
82 views

How to pass arguments of outer function into inner function implicitly?

Consider the following setup: ...
user13892's user avatar
  • 9,443
0 votes
1 answer
71 views

How to set optional variables in Function?

When using Function, is it possible to set specific arguments to be optional? For instance, in f = Function[{x, y}, x + y]; Can ...
sam wolfe's user avatar
  • 4,863
3 votes
2 answers
195 views

How to remove non-loop vertices in a graph?

How can I remove vertices from a graph that do not form a loop? For example, ...
internet's user avatar
  • 793
13 votes
11 answers
798 views

Mapping function across its arguments

Is there a more elegant way to do the following? (The code should be f-less and replacement-less) ...
azerbajdzan's user avatar
  • 18.7k
0 votes
2 answers
63 views

A polynomial with positive integer powers is being displayed as a transcedental function (LerchPhi)

I am defining a polynomial as follows: ...
Mohit Kumar's user avatar
1 vote
1 answer
172 views

Put tiny, hidden information on notebook

What is the standard method for inserting tiny, hidden information on notebooks (.nb files) ? From now on, I am planning to insert small, hidden information on every new notebook. And also for some ...
imida k's user avatar
  • 4,295
2 votes
1 answer
90 views

Distinguish .nb that has been saved from new .nb

There may be many ways to distinguish .nb that has been saved from new .nb I found that in NotebookInformation[] may be useful. ...
imida k's user avatar
  • 4,295
4 votes
5 answers
400 views

How to indicate table continuation in the middle with torn edge paper effect or something similar

I have a long table that I want to include on a PowerPoint page. I intend to truncate some data in the middle to ensure it fits on one page. How can I achieve this while indicating that the table ...
internet's user avatar
  • 793
1 vote
0 answers
108 views

Save as custom folder in menu bar in 1 step

I found the solution for myself. For some reasons I decided to write the updated content(=solution) at the top. One important reason is.. that you almost don't need to read after the solution. ...
imida k's user avatar
  • 4,295
0 votes
0 answers
52 views

Simultaneously updating functions dependent on each other

I am new to using Mathematica and am grasping for understanding of structures equivalent to looping constructs in other languages. Suppose I have 2 functions that depend upon each other and I need to ...
Enokidata's user avatar
13 votes
1 answer
541 views

Curve shortening flow

I'd like to use mma to recreate this curve shortening flow effect. I have something that works for simple shapes (LHS), but not for more complex curves, which it causes to self-intersect (RHS gif): <...
martin's user avatar
  • 8,678
1 vote
0 answers
56 views

RQ / LQ / QL of general matrices implementation in Mathematica?

Does anyone know if there are Mathematica implementations for the LAPACK routines RQ, LQ and QL factorizations for general sized matrices? It would even be great if the RQ factorization allowed a user ...
Moo's user avatar
  • 3,334
2 votes
1 answer
161 views

How can I fit rational function to data?

I have a dataset written below. I need to find a rational function that best fits this data set. How can I do it using Mathematica? The answer should be: $$f(t)=(2.196t^5+2.27t^4+2.013t^3+0.9592t^2+0....
Pabitra Tripathy's user avatar
0 votes
1 answer
67 views

Make function with variable arguments from output of symbolic manipulations

I have a fairly intricate symbolic calculation, which outputs a list of formulae as functions of several variables. The final symbolic formulae are much less complex than the large number of complex ...
Paul Harrison's user avatar
2 votes
1 answer
129 views

Symbolic multiple Integrals not delivering expected zero result

Consider the following function defined as a double-integral: $ int_{2D}(h)=\int_0^h \int_0^{t_1}f(t_1,t_2) dt_2 dt_1 $. Clearly, $int_{2D}(0)=0$ as long as $f(t_1,t_2)$ is well-behaved. The previous ...
Jam's user avatar
  • 71
3 votes
0 answers
52 views

Writing 'yield' style generator function

Just out of personal curiosity because I can't think of any solution. Probably, it's not possible, but I want a decisive answer. Is there some clever way of implementing the following function? ...
swish's user avatar
  • 7,921
0 votes
1 answer
64 views

Coordinate variable type error

I'm trying to implement a simple algorithm for curve subdivision, using a function with an input of an array of points to generate another array of new points and then putting them all into a new ...
Weyr124's user avatar
  • 15

1
2 3 4 5
50