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
111 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
207 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 ...
4
votes
0answers
80 views

Is there an elegant way of delaying evaluation of `A==B` when calling a function that uses this pattern

Suppose I wanted to define a number of functions that accepts expressions of the form: ...
3
votes
0answers
64 views

How to match the arguments of the function in any order

The issue is the following, with a dumb function with (4) arguments of (4) different heads (for each head is always no grater than one arguments): ...
3
votes
0answers
106 views

Getting Arg[z] to go from $0$ to $2\pi$

I'm defining branch cut functions, and I'm using $arg(z)$ as a building block. So I just spent an hour at the whiteboard assuming that $arg(z)$ goes from $0$ to $2\pi$, and then I implement the code, ...
3
votes
0answers
76 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
50 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
129 views

Oddify an even function and vice versa?

I want to know how to construct a function in Mathematica which would produce even analog of odd function and vice versa in closed form? The mathematical definitions are as follows: ...
2
votes
0answers
73 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
133 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
405 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 ...
1
vote
0answers
41 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
68 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
74 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
75 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
31 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
108 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
51 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
70 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
173 views

Issue with Coefficient command

I'm trying to used the Coefficient command to extract the numerical values in front of a Chebyshev polynomial. I know that there is a numerical way to do this, presented in numerical recipes, which I ...
1
vote
0answers
219 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. ...
1
vote
0answers
117 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
83 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
277 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
32 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
60 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
80 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
40 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
51 views

Iteration variable in Sum gets assigned the final iteration value

I've got a function which is defined iteratively via ...
0
votes
0answers
44 views

Multiple Integral of equation including dx prime?

I'm hoping someone can verify I've written this function properly since I'm a little new to Mathematica. What I'm attempting to do is code a function that describes a gravitational field of an ...
0
votes
0answers
32 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
52 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
37 views

How can I get the covariance result cumulatively?

I am trying to derive the covariance results for n x 4 matrix where n is an arbitrary number. I am trying to derive the covariance for each row cumulatively. For example, I am trying to derive the ...
0
votes
0answers
38 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
31 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
34 views

Doing a repeated calculation on unique chunks of data based on a value in a column

First post ever on a forum, please bear with me if I don't get it right the first time :) I'm making a script for someone that imports a data file, generates some histograms, tables, and outputs them ...
0
votes
0answers
50 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 ...
0
votes
0answers
83 views

Numerical Integration/Function

I have a problem with a function defined numerically through an integral of the form: ...
0
votes
0answers
75 views

How to define a two-variable sequence?

I would like to define the following function but I am having a problem. I would like Mathematica to "understand" what I mean by writing "+...+". For example, for large values for $n$ and $m$ it takes ...
0
votes
0answers
83 views

How to conveniently stop a programme without aborting the computation

I have a programme that will have to run for a few days. However, I would like the user to have the option of stopping the computation of the code, without aborting it, when he desires, without ...
0
votes
0answers
57 views

When to break large programmes into smaller programmes?

Say I have a main function ...
0
votes
0answers
51 views

Question about treillis structures

I have difficulties finding a command to plot multiple segments connected in nodes in Mathematica. Ultimately, my goal is to modelise something like this by entering nodes coordinates. Also, the ...
0
votes
0answers
102 views

Add constraints to a variable number of parameter in Minimize

i want to use Minimize with a variable number of Parameter which works fine: ...
0
votes
0answers
59 views

How can I avoid a scoping problem when differentiating?

I simplify my real problem as follows: I define a rule function as Clear[rule]; rule[i_] := tt -> i; the real rule function is not this simple. I define a ...
0
votes
0answers
61 views

Maximum and mean of a multi-variate function over a restricted lattice

I have a function Q, and I want to find the maximum value, the corresponding arguments for the maximum value, and the mean over a certain range of arguments. I ...
0
votes
0answers
102 views

How to save the results in an identical Excel file (.xls) in each iteration of a Do loop

Assume the following code (Below code is just an example to clearly illustrate my problem): ...
0
votes
0answers
304 views

A problem with functions and Infinite expression 1/0 encountering

Following code (function) makes integrals and then replace f[x] with Cos functions and calculate the definite parametric ...
0
votes
0answers
123 views

How can I use a For loop in a recursive function?

I am creating a simple radix2 FFT algorithm (based on Cooley-Turkey) by using a recursive function to obtain the fft. The function is supposed to work on a list (assuming the length is a power of ...
0
votes
0answers
85 views

creating some smooth density functions

I would like to create some density functions based on some distance measure $D$. As a base density function lets say I have a Gaussian density $f$ with mean $-1$ and variance $1$. I would like to ...