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.

177 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
10
votes
0answers
176 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 ...
9
votes
0answers
218 views

What is the best and most efficient way to curry?

Suppose I have a function with a signature like g[expr, _?(f), {1}, Heads -> False] and I want to access it as an operator by giving the first argument last. I ...
9
votes
0answers
115 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 ...
8
votes
0answers
159 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. [...] ...
5
votes
0answers
180 views

Finding periodic cycles of a function

Given a function f[{x,y}] it is rather simple to use, for example, NSolve to find periodic points of period $n$. We simply take ...
4
votes
0answers
575 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
319 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
73 views

What are some ways to overload Min in order for it to work with user defined expressions?

I have defined size to work with discrete size labels: ...
3
votes
0answers
67 views

Prime Matrix with determinant of powers $2^x$

Mathematica has commands for finding prime matrices, for example, here is a matrix with randoms in the range $<100$: RandomPrime[100, {3, 3}] This $2 \times 2$ ...
3
votes
0answers
48 views

Differences between u[x,y,t] vs. u[x,y][t] vs. u[x][y][t]

Is there any difference between defining a variable by u[x,y,t] or u[x,y][t] or u[x][y][t] ? ...
3
votes
0answers
255 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
156 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
383 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
117 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
340 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
315 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
131 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 ...
2
votes
1answer
53 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: ...
2
votes
0answers
50 views

How to define tensors similar to Riemann tensor in xAct xTensor xTras

I'm working on a project where we deal with objects very similar to Riemann tensor. In fact they are Christoffel symbols for higher spins. I'm using xTras for modeling problems in wolfram mathematica. ...
2
votes
0answers
58 views

How to override a built-in Mathematica function using its old version?

How can we override a Mathematica built-in function using itself in the definition? For example, the DiracDelta function is not defined for complex numbers like: <...
2
votes
0answers
55 views

How to handle Units when Integrating?

I have some functions defined, which are to use units. Now another function is used to integrate over those, with the integration variable also quantified and the input to said function. I better just ...
2
votes
0answers
51 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
97 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
61 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
104 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
35 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
36 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
104 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
69 views

3 parameter definition for solid modeling

...
2
votes
0answers
77 views

Obtaining the interpolation function of a surface

Some sample data ...
2
votes
0answers
71 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
72 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
124 views

Obtaining a Previously Constructed Function as Desired Output

I was playing around with some Generalized Trigonometric Functions defined as follows; ...
2
votes
0answers
70 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
56 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
569 views

Defining a function with a subscripted head

How can I define a function with subscript? Forexample: f_alpha[x] = 2*x
2
votes
0answers
154 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
137 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
459 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
149 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
642 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
84 views

Do Loop contained in a function defined within a custom package doesn’t work as expected but works fine when function is defined directly in a script

Below is my code and I am having problems running the StdMPC function that I am trying to define. Running my code gives me the error that the matrix A and Xopt[[i]] are not of compatible shapes for ...
1
vote
0answers
40 views

dot product of vectors with noncommutative elements

I came upon an interesting problem. Suppose you have three vectors $\psi=(a, b)$, $\phi=(c,d)$ such that their components do not commute: $ac\neq ca$, $bd \neq db$ etc. (in general the vectors may ...
1
vote
1answer
46 views

Function that accepts functions and returns an expression containing their partial derivatives

I would like create a function that takes functions as input and includes different partial derivatives of the input functions, for simplicity's sake say: $\qquad m(f(x,y),g(x,y))=f_{xxx}(x,y)+g_{xyy}(...
1
vote
0answers
135 views

General:: Exp[-717.401] is too small to represent as a normalized machine number; precision may be lost

I am solving pde. For the post processing bvp, there is solution given in output which is the solution from mathematica version 10.0.1. Output from above in mathematica 10.0.1 is, But when the similar ...
1
vote
0answers
46 views

Passing python data types as function arguments

I've a few python data types ...
1
vote
0answers
46 views

How to find the Inverse of numeric Function that was created from NDSolve

I'm a newbie to Mathematica and i do have a simple question. I have a function H that was created numerically as solution form NDSolve (like H(R)), and i'm trying to create the Inverse function R(H) ...
1
vote
0answers
82 views

Approximation of a function by a polynomial (Chebyshev First Kind, Bernstein, etc…) containing only even degrees and constants in a given Range[a,b]

In Mathematica, how can I create a polynomial function containing only even degrees and constants? That is, I have a function: $f(x)=\frac{\pi ^2}{\left(\frac{\pi }{2}-\tan ^{-1}(k (x-1))\right)^2}$ ...
1
vote
0answers
46 views

Using `Block` with Conditions `/;`

I would like Block to run conditionally. I understand how to do one condition, but what about an AND operation? e.g ...