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.

learn more… | top users | synonyms

6
votes
0answers
175 views

Fine tuning compiled code that computes dilogarithm function

As an exercise of writing a good Compile function, I want to do the simple task of coding a routine that outputs the real part of the dilogarithm function ...
5
votes
0answers
79 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 ...
4
votes
0answers
245 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
84 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
62 views

How to build a ColorFunction that can take a non-numeric value? Blend returns an error

I'm trying to use an external package, defined here. This package has a private function called makeColorFunction that essentially works by taking an input color ...
3
votes
0answers
103 views

Obtaining a Previously Constructed Function as Desired Output

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

How to combine DifferenceRoot objects for odd and even-indexed terms

I'm trying to analyze a certain infinite sequence $S$, indexed by positive integers starting from $1$. It can be split into two subsequences: $S^{odd}$ by removing all even-indexed elements and ...
2
votes
0answers
57 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{...
2
votes
0answers
50 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
93 views

Construct single InterpolatingFunction from a mathematical combination of other IF's

Let's say I have an interpolated function f, like I might get as the solution to an NDSolve: ...
2
votes
0answers
83 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
0answers
286 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
137 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
482 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
69 views

Build basic Adobe Kuler-type construction: improving performance / speed

Adobe Kuler is a useful web tool to create colour palettes, but it is limited to 5 colours. I am trying to make a basic Kuler-type construction, but it is very slow, and crashes on my computer for > ...
1
vote
0answers
36 views

Symmetrize a function

I am working with a function in several variables. I need a function which symmetrizes it. Namely in case of two variables it is f[x, y]+f[y, x]. For three variables it is $$f[x , y , z] + f[x, z, y] ...
1
vote
0answers
45 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 $...
1
vote
0answers
50 views

Mapping over two indices with a condition

How can I use Map over two indices with a condition? I am trying to calculate second derivative of an eigenvalue, $\lambda_i(x)$, of $n \times n$ matrix $M(x)$ ...
1
vote
0answers
50 views

Piecewise in 2D with quadrants as conditions

I am trying to define a piecewise vector field. Can the condition be of the form I am using (i.e. a quadrant)? I can't also make Piecewise work with more than two ...
1
vote
0answers
57 views

Defining a function with a subscripted head

How can I define a function with subscript? Forexample: f_alpha[x] = 2*x
1
vote
0answers
113 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 ...
1
vote
0answers
103 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 ...
1
vote
0answers
79 views

What are the differences between these functions when used for NMaximize?

In short, the question is how to construct the function you want to optimize? ...
1
vote
0answers
32 views

How to make Expand work right in a function definition?

This works just fine: Derivative[n_, 1][g][x_, v_] := D[g[x, v], {x, n + 2}]/2 + D[D[g[x, v], x]^2/2, {x, n}]; h = Expand[D[g[x, v], {v, 3}]] I would like to ...
1
vote
0answers
120 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 ...
1
vote
0answers
66 views

A more efficient way of fitting a non-linear model that returns an entire list?

I have a function that takes two parameters, del and nu, and returns a list npoints long ...
1
vote
0answers
87 views

Function behavior based on Head

I'm figuring how to implement a function behavior based on the Head of its argument. I mean ...
1
vote
0answers
150 views

How to insert a function into OptionsPattern?

I’ve written a function TableauForm to draw a standard Young Tableau. This problem is related to this one, however, the difficulty is that, a function has to be applied to the list in my case. This ...
1
vote
0answers
85 views

How can I compile function with Apply?

For example, I tried to compile this function but Mathematica gives "The only function arguments supported are Times, Plus, or List", I have no a way to compile this. ...
1
vote
0answers
324 views

Return Functions from parallel execution of module

I wrote a module which numerically solves an ODE using NDSolve. The result from this is e.g. either ...
0
votes
0answers
64 views

How to compute this integration?

I would like to compute the following integral: I tried to write it as ...
0
votes
0answers
52 views

What I make wrong with Module command;

I have a differential equations that I have to solve in two parts.e.g: ...
0
votes
0answers
43 views

Greatest common denominator command. Can you explain why this command works?

Can you explain how this function works? mysteryFunction := Fold[#/#2 /. {n_~_~_ -> #/n, _ -> #2} &, #, {##}] &
0
votes
0answers
48 views

How to calculate a continuous function once and access values later?

I have a function that involves a numerical calculation: h[v_]:=NIntegrate[f[x]*Log[p[x, v]], {x, -Infinity, Infinity}] I need to visualize how well a bunch of ...
0
votes
0answers
59 views

Considering special cases in general definitions

I want to calculate some coefficients $\qquad B_k = 2\int_0^1 u(x) \cos(k\pi x)\,dx$ for $0<k\in\mathbb N$ and I am doing this in the following way: ...
0
votes
0answers
56 views

break down the function

I am using Series function, but I found that it cost too much time. Since the Series function is Taylor expansion and I only need first order, I want to break down the code, so I can make it faster <...
0
votes
0answers
58 views

Normal ordering in Mathematica

I want to create a function which normally orders a string of field operators. Consider the following: $$\langle0\vert\hat{a}(k_n) \cdots \hat{a}(k_2)\hat{a}(k_1)\hat{a}^\dagger(k_1)\hat{a}^\dagger(...
0
votes
0answers
55 views

Problems with Tooltip

I an getting strange behavior with functions built using Tooltip. I create a function to display the position of data in a list ...
0
votes
0answers
49 views

Improving numerical stability of the Goldstein-Price Function

Goldstein-Price Function is a two-dimensional test function for optimization, defined as $$f(y,z) = \left(\left(3 y^2+2 y (3 z-7)+z (3 z-14)+19\right) (y+z+1)^2+1\right) \times \left(\left(12 y^2-4 y (...
0
votes
0answers
40 views

Dot production associated with comparison process of different matrices eigenvectors

With thanks to Guess who in the link module using.. We created functional 5*5 matrices: ...
0
votes
0answers
79 views

Inverse Superposition

There are 4 tables that, I have written them as bellow: (m, n, s, and r are orthogonal basis. r.r=n.n=m.m=s.s=1, and m.n=n.r=...=0). a's, b's, c's and d's are coefficients and are numeric values. <...
0
votes
0answers
95 views

How to make a twice-differentiable function that approximates some data?

I have some time series data that I would like to approximate with a twice-differentiable function. Each time series has ~10,000 datapoints, so I definitely do not want a function that passes through ...
0
votes
0answers
49 views

Constructing a function for expanding general $n$ products

I have the following quantum mechanically motivated product: $\langle0\vert(A_1b_1 + A_2b_2 + A_3b_3)(B_1b_1 + B_2b_2 + B_3b_3)(C_1b_1 + C_2b_2 + C_3b_3)$, where $b_i$ is an annihilation operator ...
0
votes
0answers
72 views

How to create a big jacobian matrix function over some variables of a vector function?

Suppose I have a vector function of $n$ components and it has $n+m$ arguments, $$\vec{f}(x_1,x_2,\dots,x_n, y_1, y_2, \dots, y_{m})$$ where $n, m $ are around 10. I want to create a Jacobian matrix ...
0
votes
0answers
108 views

Piecewise function output response interpretation

Piecewise[{{t^2, t <= 0}, {t, t >= 0}}] Outputs: t^2 t <= 0 t t >= 0 0 True What does the last line of output 0 True mean? Sometimes it ...
0
votes
0answers
51 views

NestList on a function where one of the arguments is chosen by the user

I need to NestList a function where the user chooses one of arguments. Here it is an example: ...
0
votes
0answers
42 views

How to evaluate NMinimize inside a function

I want to define a function that returns a sum of differences of some points to a given function. To obtain these differences I would like to use NMinimize, but if I implement that straightforwardly, ...
0
votes
0answers
59 views

How to Fold (FoldList) this in a more compact (efficient) way?

Example code: x = Table[something[i], {i, 5}] Table[Fold[f1[#1, f2[#2, a], a] &, x[[i]], {c1, c2, c3}], {i, Length[x]}] This above is just an example. I ...