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.

Filter by
Sorted by
Tagged with
1
vote
1answer
43 views

Why does this DeleteCases not work?

I believe this is simple but I couldn't figure out why this doesn't work. Everything looks good to me. ...
0
votes
1answer
86 views

Defining a function in Mathematica without functional form [closed]

I am trying to define a function $H(s)$ in Mathematica, but the only restrictions/information on this function are that it is a concave and increasing in $s$, which is defined over the interval $[0,S_{...
2
votes
1answer
77 views

How can I make this plot easier to see?

How can I make this plot easier to see? In this plot the waverform is not clear. If I plot with w only from 0 to ...
3
votes
4answers
109 views

Construct Function[ ] from String based formal arguments

If wee look at: x=11 f=Function[{x},x^2] f[5] we get: 11 Function[x, x^2] 25 as expected. Now suppose we want to create the ...
-2
votes
0answers
37 views

How can we write code to find the number of patterns except impossible code? [duplicate]

I'm writing a code to find the number of lock patterns on my Android phone. In 3.가능한 패턴의 경우의 수(Number of possible pattern cases), How can we write code to find the number of patterns except impossible ...
0
votes
2answers
45 views

How can I use a function defined by another function? [closed]

I'm trying to define a function with another function. First I define f[{x1_, x2_, x3_}] and g[{x1_, x2_, x3_}] and I do some ...
0
votes
2answers
43 views

How to make the third parameter optional and adding some condition?

I have a function as follows. The function has 3 parameters. Now I would like to make the third parameter i optional. So you call call it like ...
3
votes
2answers
350 views

How can I make a 3D Bode plot of a function?

I'm trying to do a Bode plot in 3D for the function below, but there is no built-in function for that. How can I do that? It would also be nice if you could use a mesh to make it easier to see. ...
0
votes
1answer
29 views

How to write a function taking limit of multivariables in sequence?

I'm trying to write a function to calculate the limit of a function on a number of variables in sequence. Here I take a function with four variables x, ...
0
votes
0answers
63 views

How to use my code to calculate the following?

(Don't consider the context of this problem. Help with what you know and focus on the coding.) Consider the following: If $S=\left\{\frac{m}{2n+1}:m,n\in\mathbb{Z}\right\}$, $g:[0,1]\to[0,1]$, and $\...
0
votes
3answers
72 views

Two “identical” functions returning different values

When taking the norm of a complex number in Mathematica you get the same result when you use the Norm function or the Abs function. So why do the following two functions (kp and kpp) return different ...
0
votes
0answers
52 views

Construction of Navigation Function: Error

https://en.wikipedia.org/wiki/Navigation_function https://www.sciencedirect.com/science/article/abs/pii/S0921889015302451 https://arxiv.org/pdf/1605.00638.pdf - Paragraph III I am trying to create a ...
2
votes
1answer
41 views

Why are the inputs not being applied to the function in this MWE?

Consider the following MWE ...
0
votes
0answers
44 views

Best way to simplify a polynomial before making it the body of a function?

So, I'm dealing with iterated polynomials of a single variable—say they're anonymous functions labeled as $p_i$, i.e. p[1], p[2],...
0
votes
0answers
20 views

`FunctionLayer` will calculate a distance matrix

I would like, that a FunctionLayer will calculate a distance matrix between two vectors. I try a following approach: ...
4
votes
1answer
52 views

Best way to write a function that randomly takes definition from list of functions?

I want to define a function based on a random choice from a list of possible functions. For example, suppose the possible functions are {Sqrt,Log}. Then I want to ...
1
vote
1answer
30 views

Use result of function without repeatedly evaluating [closed]

I have a function which takes the determinant of a matrix whose values depend on two parameters: f[x_,y_]:= Det[M[x,y]]; where M is a predetermined matrix which is ...
0
votes
0answers
57 views

Spheroidal Harmonics

There is a (scalar) field P varying on a spheroid (squashed) surface. This field is a function of four independent components ...
2
votes
1answer
75 views

My function has an integral in it. How can I calculate and plot it?

I'm new to using mathematica, but I want to do a plot of this equation below: $$ F(\nu) = \frac{4 \pi h \nu^{4}}{c^{2}} \int_{r_{i}}^{r_{o}} \frac{r d r}{\exp \left[\left(\frac{3 \pi}{2}\right)^{1 / 4}...
0
votes
2answers
38 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 ...
1
vote
1answer
63 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 ...
1
vote
1answer
113 views

check a sequence in Pi

I read that the string 36541622473 occurs in π(pi) at position 36541622473, counting from ...
1
vote
1answer
54 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 ...
0
votes
0answers
21 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 ...
0
votes
0answers
48 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?
1
vote
1answer
88 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 ...
0
votes
2answers
53 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 ...
0
votes
0answers
29 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 ...
0
votes
2answers
31 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 ...
4
votes
1answer
80 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}$, ...
6
votes
0answers
149 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 ...
0
votes
0answers
33 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%...
0
votes
1answer
60 views

Get position while matching pattern

I want following imaginary feature : PositionOf Example1) ...
0
votes
2answers
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 ...
1
vote
1answer
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} ...
2
votes
1answer
21 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 ...
0
votes
2answers
38 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 ...
4
votes
2answers
115 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 ...
1
vote
1answer
40 views

Apply function using level

The following use of Level is documented, without any example. Let's try some simple codes : ...
2
votes
2answers
105 views

Restrict kinds of heads when dealing with level concept

In[1] Map[(# + 7) &, {a, 3 b, {c, d}, e}, {2}] Out[1] {a, 10 (7 + b), {7 + c, 7 + d}, e} But I want feature like ListMap : ...
3
votes
2answers
127 views

Why does f[set_]:=AppendTo[set,5] not work when applying f to a set?

The following code works ccc = {}; AppendTo[ccc, 5]; ccc and gives the output {5} However, the following code does not work: <...
4
votes
2answers
711 views

Can this notation be computed in Mathematica?

I defined a notation as follows: (a, b) = $a^b$, (a, b(c)) = (a, b-1(c)) * (a+1, b(c-1)), (a, b(0)) = (a, b), and (a, 1(c)) = (a, a(c-1)). For c = 4, (a, b(c)) is already tedious to evaluate. I next ...
2
votes
1answer
134 views

Automatically blend colours to a match

I have a restricted palette (hue values given below) ...
4
votes
1answer
129 views

Construct 1 variable function from given 2 variable function

Given a function f[x , y]. The definition of f is not self-describing. (f was defined with objects other than f.) Then I want to construct a function g[x] such that f[x,y] and g[x][y] are the same, ...
0
votes
1answer
55 views

Sieve of Sundaram Help

I am attempting to implement the Sieve of Sundaram: Start with the list of integers 1,2,...,n. For every pair of integers (i,j) satisfying 1<=i<=j and i+j+2ij<=n, remove the number i+j+2ij ...
2
votes
1answer
31 views

(Mathematica newbie) How to avoid this error ? Animate with predefined and nested functions [closed]

So im trying to do the Atwood machine for project and I try to do it as simple as possible. I defined a graphical functions for elements and also a function of move equation. ...
0
votes
1answer
51 views

Checking variable A is determined. (DeterminedQ ?)

How can we (loosely) check whether variable A is determined, not directly computing A ? (= How can we define DeterminedQ function ?) For example, ...
3
votes
1answer
61 views

Creating a dynamic piecewise plot

I'm trying to create a dynamic piecewise function. I can get 3 points, but after that, everything gets a bit complicated: ...
1
vote
0answers
55 views

Defining function recursively with increasing variables

I am exploring my question l,r-operations on words $[[[1,2],3],4] \cdots, n]$, $[1,[2,[3,\cdots, [n-1,n]\cdots ]]]$, through some sample implementation. As a trial, I built ...
2
votes
2answers
66 views

Building dynamic functions

When I'm trying to build Dynamic functions (as in this question), I often end up with long repeated lists of dynamic variables, like this: ...

1
2 3 4 5
41