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.

2,134 questions
Filter by
Sorted by
Tagged with
134 views

Is there a way to do this more efficiently?

I'm trying to write this Mathematica function to find the optimal price for a model, given some model parameters. This is a stylized example of what I'm trying to do, and I'm wondering what's a better ...
59 views

RegionPlot Calling User-Defined Function Not Working

This is following up on this post: Function not evaluating as expected I am trying to make a RegionPlot with Manipulate in which ...
48 views

Function not evaluating as expected [closed]

I'm not sure I understand why this is not working and why it's giving different answers: A simple example illustrating the issue is below: ...
65 views

41 views

Function providing input and integration limits for NIntegrate

I am trying to define some custom function that evaluates the numeric integral of some complicated function. The problem is that I would like to include as an input the integration limits. A MWE ...
67 views

NDSolve needs multiple executions to work and is very slow

I just simulate a system and use an Extended Kalman Filter to estimate the state. Everything works, but I don't understand why I need to execute the Ndsolve command two times before it can run without ...
120 views

check a sequence in Pi

I read that the string 36541622473 occurs in π(pi) at position 36541622473, counting from ...
61 views

StringTrim differently from left and right

Is there a function to trim a string with a different pattern for the left and right side? (I seem to remember it but perhaps I am thinking of another language because I can't find it in the ...
26 views

Convert function to convex on infinite range, knowing gradient and hessian

Let's take a function $f=sech(x)$ as an example. It is strongly convex in a limited range of $x$. It is further assumed that: $f$ is a "black box", $x$ as input ; output is the value of the ...
49 views

How to partly symmetrize a multi-variables function

For example, I want to symmetrize the variable x and z in the three-variables function f(x, y, z).I expect to obtain 1/2 f(x, y, z)+1/2 f(z, y, x). How to achieve this in Mathematica?
90 views

How to define a function like 1/f(x)

I'm trying to define a function f(x) such that 1/f(x) = 1/R - A/B. I know that I can just work the RHS out so that ...
55 views

What pattern will distinguish an element of a list from a list when used in a function?

In Mathematica several versions of a function can have the same name with a pattern distinguishing which version of the function should be used for which type of input. Here is a minimum working ...
58 views

Standard way to define a linear operator?

Say I want to define some simple linear operator. I can do this by f[c_?NumericQ x_] := c f[x] f[x_ + y_] := f[x] + f[y] Or let's define a bi-linear operator ...
49 views

Normalize an L(s, d) function for fixed s

I have the following function L: σ = 9; L[s_, d_] = (1/(σ*Sqrt[2*\[Pi]]))*E^(-(1/2)*((s-(-50-11*Log[d]))/σ)^2) This function L describes basically for some ...
89 views

Force EllipticTheta to "use" $(e^{\pi i\tau})^{\lambda}=e^{\pi i\tau \lambda}$

Define $\theta_2 (q)=2\sum_{n\ge 0}q^{(n+1/2)^2}$ and $\theta_3 (q)=1+2\sum_{n\ge 1}q^{n^2}$, $q=e^{\pi i\tau}$, $q^{\lambda}=e^{\pi i\tau \lambda}$, $q\in\mathbb{C}$, $|q|\lt 1$, $\tau\in\mathbb{C}$, ...
189 views

CORDIC - Volder's algorithm

As the title suggests, the object of this topic is the CORDIC algorithm (COordinate Rotation DIgital Computer). Although it's now obsolete in most cases, I think it can be interesting to understand ...
36 views

Simplify function to find rate constants

I have a function to calculate rate constants using nonlinear least square modeling from a 2011 paper by Jia et al. https://www.cell.com/cell/fulltext/S0092-8674(11)00536-8?_returnURL=https%3A%2F%...
67 views

Get position while matching pattern

I want following imaginary feature : PositionOf Example1) ...
25 views

Version Differences in Chain Assignments for Variables Defined using SetDelayed?

In trying to improve my Mathematica programming skills I have been methodically going through Leonid Shifrin's (2008) Programming in Mathematica: An advanced introduction. In Section 2.4.3 he ...
34 views

How to assign very large outputs to function for evaluation at points?

I create a very large output D[x^100*E^(2*x^5)*Cos[x^2], {x, 137}] I want to assign this to a function as ...
33 views

Joining each element of second tuples to the end of each element of the first tuples [closed]

How can I generate a new tuples by joining each element of tup3 to tup1? For example joining {0,1,1,1,0,-1} from tup1 and {d,0,1} from tup3 to generate {0,1,1,1,0,-1,d,0,1} ...
38 views

Any way to use Set and/or SetDelayed to index a set of Fit functions?

I was a bit curious if anyone knows of any compact way to use Set and/or SetDelayed if we want to, say, generate Fit functions and index them as well. To demonstrate what I had in mind, consider the ...
44 views

Defining function in terms of previously defined symbol

With a very high frequency I find myself working with giant and hard to alter expressions in a situation where it would be convenient to do something like ...
126 views

bind specific 'Slots' to specific 'Map'

Is it possible to construct a pure function using multiple slots, with the following concept :       Binding   specific slot    to    specific apply or map For example : In this example, To ...