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
2answers
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 ...
0
votes
0answers
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 ...
1
vote
0answers
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: ...
1
vote
1answer
65 views

How can I pass a list as an index set for product

I want to evaluate a Blaschke product based on the set of zeroes, and compute its preimage for some points. The Blaschke Product looks like: $$B(z) = z^n\prod_{a_k\in \text{zeroes}} \frac{z - a_k}{1 - ...
0
votes
0answers
45 views

How to reconstruct a complicated built-in function (e.g. for modification or use in a version that does not have it yet) [duplicate]

Is it possible to extract the definitions for a built-in function to reconstruct a similar user defined function. This would be useful to port new mathematica functionality to older versions or to ...
8
votes
1answer
460 views

very simple but unexpected aspect of Function[ ]

I've always thought (2#+1)& and Function[x,2x+1] are interchangeable in common sense. But, ...
1
vote
1answer
55 views

Defining a two-variable function with a parity property

I would like to define a function that has the following property $f(-x,y)=f(x,-y)$. An example is $f(x,y)=x y$. For simple inputs, I can impose this easily enough as: ...
2
votes
1answer
82 views

A function that modifies functions - well-defined operation?

Here's my basic setup: Say I have a list of specific symbols and a function noSymbol, which accepts a mathematica expression and checks whether any symbol from my ...
1
vote
2answers
93 views

How to work symbolically with a compiled function?

I have a compiled function f to be used as a piece of a much larger calculation. I would like to expand out a function that calls ...
0
votes
1answer
84 views

how can I modify this function to convert to polar form for any complex expression?

The function from another post is to convert a complex number to polar form. polarForm = Expand[# /. z_?NumericQ :> Abs[z] Exp[I Arg[z]]] & Now if I apply ...
3
votes
2answers
551 views

How to generate all possible functions combinations

Assume that I have 3 functions like this (total 10 functions in reality). f1[x_] := 3 x; f2[x_] := x^2 - 1; f3[x_] := 2 x + 5; Now I want to generate all possible ...
2
votes
1answer
95 views

Why does this DeleteCases not work? [duplicate]

I believe this is simple but I couldn't figure out why this doesn't work. Everything looks good to me. ...
0
votes
1answer
93 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
83 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
120 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 ...
0
votes
2answers
48 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
391 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
37 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
66 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
78 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
55 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
42 views

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

Consider the following MWE ...
0
votes
0answers
46 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],...
1
vote
1answer
59 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
59 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
31 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
66 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
78 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
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 ...
1
vote
1answer
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 ...
1
vote
1answer
120 views

check a sequence in Pi

I read that the string 36541622473 occurs in π(pi) at position 36541622473, counting from ...
1
vote
1answer
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 ...
0
votes
0answers
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 ...
0
votes
0answers
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?
1
vote
1answer
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 ...
0
votes
2answers
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 ...
0
votes
0answers
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 ...
0
votes
2answers
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 ...
4
votes
1answer
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}$, ...
6
votes
0answers
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 ...
0
votes
0answers
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%...
0
votes
1answer
67 views

Get position while matching pattern

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

Apply function using level

The following use of Level is documented, without any example. Let's try some simple codes : ...
2
votes
2answers
125 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 : ...

1 2
3
4 5
43