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.

144 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
9
votes
0answers
108 views

Fast Destructuring

This might be a XY problem. I first post my immediate question and some background below. Question: What's the fastest way to pass arguments matching ...
9
votes
0answers
154 views

Does Compilation option “InlineExternalDefinitions”/“InlineCompiledFunctions” lead to unnecessarily complicated nesting?

Question: When an external (possibly complicated) definition f is used inside a compiled function with ...
8
votes
0answers
145 views

KeyValuePattern specificity in DownValues

Bug introduced in 10.4.0 and persisting through 11.3.0 CASE:3824590 [...] Developers are discussing this behavior. [...] I will let you know when I have definite information on this. [...] ...
4
votes
1answer
46 views

Computing Higher Order Tensor of Variable Rank

The following code takes a vector x of variable length, computes the outer product of the vector with itself to form the matrix $\rho$ of dimension $2^n \times 2^n$....
4
votes
0answers
394 views

Wick Contractions; help with a piece of code

An alternative title to this thread could be, understanding another person's code. A few years back there was a workshop on Mathematica and applications to theoretical physics; if you want I can ...
4
votes
0answers
314 views

Strange behaviour of MMA in derivatives of some standard functions

There are some peculiar things to be discovered in derivatives of some standard functions in MMA: Strange behaviour Example 1: Abs We have ...
3
votes
0answers
200 views

How to achieve with Mathematica the effect a closure has in other languages?

Motivation I want to write an auxiliary function (brief auxf) for testing the output of another function that evaluates its body repeatedly using ...
3
votes
0answers
74 views

What's the role of the lines order in defining a function?

I'm totally surprised by the finding I had never noticed before. This code works as obviously intended ...
3
votes
0answers
149 views

How to reduce computation time for a large symbolic matrix

I have a 6x6 matrix (A) that is a function of k and H with complex symbolic entries that contain functions. I want to reduce the computational time since I will be evaluating the matrix many times for ...
3
votes
0answers
349 views

Generating a list of random numbers that follows a pattern

I'm a beginner to Mathematica. I'm writing a code to design a 4-bar linkage mechanism that traces a path in 2D space. I got the modelling done right, now I'm writing my own implementation of a genetic ...
3
votes
0answers
116 views

How to get this terrible summation/product to run in Mathematica?

I've come across this formula and have no idea where to even start. (My assumption here is that $m,n$ are known and input into the expression to arrive at an answer.) $$f(m,n) = \sum_{\substack{0 \...
3
votes
0answers
250 views

Lyapunov Exponent as a function of parameter

I am working at Rossler system and I would like to ask you for some help. This system is described by equations: \begin{array}{ll} \dot{x} = -y - z \\ \dot{y} = x + 0.2y \\ \label{eq:UkladRosSP} \dot{...
3
votes
0answers
273 views

How to Implement a “Function Object” suitable for NDSolve and Finite Element Method?

I have a bunch of methods that shoud return an expression that behave like a function, i.e. an expression that, when supplied with suitable arguments, evaluate to something. A simple ...
3
votes
0answers
125 views

How to make a new analytic function work seamlessly with Mathematica's analysis functions?

I am defining a new analytic function of six variables. I have algorithms to evaluate it numerically, and have amassed a large catalog of analytic properties. It is easy for me to program the ...
3
votes
1answer
54 views

How to convert output from Reduce into a piecewise function?

Reduce often provides a much fuller solution than Solve. But it's always in the form of a true statement rather than functions ...
2
votes
0answers
42 views

Speeding up the process of NDSolve[] when a user-defined function is involved?

I am trying to tackle a (1+4 dimensional PDE) model at which the solution of the first PDE (with some interpolations and changing the domain) would be used in the second PDE. In fact, I must choose ...
2
votes
0answers
74 views

Lambda calculus reduction in Mathematica

Are there any built-in functions for reducing lambda terms in Mathematica? If not, how might one do it? I've heard of Function, which is good for $\beta$-reduction, ...
2
votes
0answers
49 views

Fast way to check if an expression matches any of the rules in a list?

I have a function defined roughly like so. This is a minimum recreation. foo[expr_, rules: {__Rule}] := "some fancy result" /; AnyRuleMatchesQ[expr, rules]; What ...
2
votes
0answers
82 views

Why does the evaluation of “Catch[Break[],\$Failed]” not return “\$Failed”?

Under normal conditions, evaluating something that emits a Message eg the evaluation of 1/0 that produces a ...
2
votes
0answers
31 views

Keyed eigensystem for nested Association

Suppose a matrix is given where both rows and columns are keyed, for example this correlation matrix: ...
2
votes
0answers
30 views

Scoping of OptionValue for inner functions in closures

Assume a function f is a closure over an inner function g. Both f and ...
2
votes
0answers
76 views

Defining a function by coordinates of points and degree of a polynomial

I'm studying about solid of revolution. In these studies, I learned that to get the volume of such a solid, I need to know $f(x)$ to describe the contour of the profile. This concept I understood. $...
2
votes
0answers
67 views

3 parameter definition for solid modeling

...
2
votes
0answers
67 views

Obtaining the interpolation function of a surface

Some sample data ...
2
votes
0answers
62 views

Built-in functions for Homotopy group

Does Mathematica have built-in functions for Homotopy group, for example for computing $$\pi_n(S^m)=?$$ or more generally $n$-th homotopy group, $$\pi_n(X)=?$$ for some $X$. (I search, but I could ...
2
votes
0answers
68 views

Is there an efficient way to monitor the progress of a task remotely?

Recently, I've been running Mathematica packages on a remote cluster using SSH (using, e.g. the command ...
2
votes
0answers
123 views

Obtaining a Previously Constructed Function as Desired Output

I was playing around with some Generalized Trigonometric Functions defined as follows; ...
2
votes
0answers
67 views

First position of incremental series

I am still a beginner and maybe I want to do something too complicate! After 29 cycles I obtained the following events list: ...
2
votes
0answers
53 views

Rescale large numerical factors in rational functions

Given a rational function $$ f(x_1,x_2) = \dfrac{r_1 x_1^2 + r_2 x_2}{r_3 x_1 + r_4 x_2}, $$ with $r_i$ arbitrary real or complex numbers, is there a built-in function to get Mathemtica to rewrite as $...
2
votes
0answers
147 views

Find algorithm or generator formula with automated procedure and pattern recognition

I am trying to find a generator formula for the discriminant of a polynomial and believe it would be an interesting problem for the Mathematica community to know how to automate evaluation of certain ...
2
votes
0answers
134 views

How to create a complex variable from dated list values

Can anyone help me to construct a variable "PI" from values of variable x. Variable x represents a group of two time series rj and ri on equal dates(joined two dated lists with states).Variable x have ...
2
votes
0answers
453 views

Positive integrand giving negative answer

I'm integrating a positive function f(t) times sin(t) from 0 to pi/5 and get -38. Actually f is slightly negative for a short time (smallest value ~ -0.0005), but far from enough to explain this. ...
2
votes
0answers
147 views

correct usage of ParallelTable

I am trying to parallelize my script. Here is a MWE of how I have done it: ...
2
votes
0answers
626 views

Generating a function which outputs possible chemical reactions

I want to make a list of chemical reactions and I write them down in a $\require{mhchem}\LaTeX$ format. They are of the following form $$NA_n^i+MB_m^j \rightarrow \hat NA_{\hat n}^{\hat i}+\hat MA_{\...
1
vote
0answers
62 views

Find all pattern in expression

Consider this problem: I have a functional $\mathcal{F}$ acting on some function $n(t)$ such that $$ \mathcal{F}[n(t)]=0 $$ $$ \mathcal{F}[n^*(s)n(t)]=\alpha(t,s) $$ $$ \mathcal{F}[n(s)n(t)]=0 $$ ...
1
vote
0answers
37 views

Make a function invariant under a permutation of the arguments

The output of my current notebook contains expressions that look as follows (V[{k,q},{s,t}] + V[{-k, -q}, {t,s}]) In my specific application these two functions ...
1
vote
1answer
98 views

How to use Manipulate in filter design to plot the sum two raised-cosines?

I would like to be able to add a raised cosine to a "standard" raised cosine. With a time delay which I could manipulate (so the shape of the standard cosine function is altered, meaning the function ...
1
vote
0answers
48 views

How to simplify Log expressions using rules

I have the following expression, ...
1
vote
0answers
37 views

Gauss elimination, reordering rows based on pivot values

I'm trying to create a code for Gauss elimination such that if there's a zero pivot during elimination, the equation will be reordered with the next row with a non-zero element and if it can't do that ...
1
vote
0answers
59 views

Series doesn't seem to work on functions

When you try to use the Multivariable option of Series, it doesn't work as intended, since it keeps terms of higher order than intended. Example: Expand a two-variable gaussian exponential to second ...
1
vote
0answers
77 views

Is it possible to modify the behavior of Listable?

Is it possible to achieve Thread-like behavior using the Listable attribute either on a symbol or in a pure function (or ...
1
vote
0answers
34 views

Store and recall multiple defined functions from the cloud

I am fairly clear on how to define my own functions in Mathematica. I have also read the several questions on here about how to create a package so those defined functions can be recalled ...
1
vote
0answers
47 views

Defining an abstract multiplication over finite indices

I would like to define a map (a "multiplication" denoted $\otimes$) over the finite set of symbols $G=\{a,b,c,d,e,f,g,h\}$. I would like to define several rules like $$a \otimes b= \{b \} $$ $$a \...
1
vote
0answers
50 views

Mapping over array/matrix the efficient(compact) way

Update In short, I have myCAans[[1 ;; 5]] like this: {{0, 0, 0, True, 0, 0, 0, 0, True, 0, "T0", 39}, {0, 0, 0, True, 0, 0, 0, 1, True, 1, "B", 101500}, {...
1
vote
0answers
53 views

Is there a way to order the QZ(or Gen. Schur) decomposition in mathematica?

Let's imagine I have two matrices $\Gamma_0$ and $\Gamma_1$. The SchurDecomposition function in mathematica will return matrices $Q,\Lambda, Z, \Omega$, such that $...
1
vote
0answers
66 views

Recursive functions with integrals/derivatives return wrong results

I have the following recursive functions: ...
1
vote
0answers
117 views

Problem with Wick Contraction

I'm trying to compute wick contractions knowing that: $\langle a_a a_b \rangle = \delta_{ab}$. So far I've the following ...
1
vote
0answers
93 views

Evaluate a precision-sensitive function

I want to define a nice function Φ in 3D that is computed as follows $$ \phi (x, y, z) = - z + \frac{\sqrt{32}}{\pi} \sqrt{\cosh \nu - \cos u} \sum_{n = 1}^\infty ...
1
vote
0answers
46 views

Multiple Square Bracketed Function definition

I am familiar with the typical way of defining a function--such as f[x_,y_]:=x+y but I have not found a discussion of definitions such as ...
1
vote
0answers
174 views

Return unevaluated expression from function

Is there any way (except using upvalues) to make a function that returns it's input Unevaluated? What I mean by that: Take the following example: ...