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
5
votes
4answers
54 views

An anonymous function with constraints

I'm not very good at working with anonymous functions, a fact that has now come back to bite me. Suppose I have a function defined as follows: ...
4
votes
2answers
233 views

How to condition arguments of a pure function?

I would like to exclude the point {x=0,y=0} in the function definition ...
16
votes
4answers
1k views

How to straighten a curve?

What's the easiest way to get the following animation for a given parabola where the arc length is preserved (that is, for two points in the parabola, I straighten it as follows) My main goal is the ...
0
votes
0answers
47 views

Defining function with arbitrary length [closed]

I want to make some function with whose input is an arbitrary length of a list. For example, what I did in for explicit case as follow ...
3
votes
2answers
124 views

What is the usefulness of adding a colon “:” to arguments in the declaration of a function?

I'm studying a code with the following function declaration : FindChain[ x:__ ,y_?FindChainQ,z:__] := { {x},y,{z} } What is the meaning of the colon ":" after the arguments x and z ? What ...
0
votes
2answers
77 views

Writing a wrapper function computing the memory in use

Is there any way I can write a wrapper that wraps around a piece of code and evaluates how much memory has been used after the execution? Ideally I would like a function that performs the following ...
6
votes
0answers
63 views

Why does Longest not work on OptionsPattern?

When having a function with optional arguments and options, I frequently find myself writing something like this: ...
2
votes
2answers
91 views

Find the range of a univariate function over a specific interval of the variable

I would like to find the range of the function below, but only for values of $a$ strictly greater than zero. ...
0
votes
1answer
34 views

Restrict the domain of a function (and plot) it) when it depends on the value of a parameter

I know similar questions have been asked, but I am very new at Mathematica and other questions/answers are quite complex and do not suit the code I want to write. I want to restrict the domain of the ...
0
votes
0answers
39 views

A Function of Arguments or a Function of a List of those Arguments – Which is Recommended?

Which is recommended from a programming perspective and has better performance in memory and speed given guaranteed identical output – a function taking many arguments and then referring to those ...
3
votes
2answers
82 views

Passing Arguments or Passing a List and Referring to its Parts – Which Gives Better Performance?

Which is better for optimizing speed, memory, and coding "safety" – passing arguments to a function or passing a list to the function and call the list's parts? That is, which of the ...
-2
votes
0answers
30 views

Calculate residues at points being rounded (function not rational) [duplicate]

I have a non-rational function $$f(z)=\frac{1}{799. \left(\frac{1}{z}-0.85\right)-798.999 \sqrt{\left(\frac{1}{z}-0.85\right)^2-0.000196}-0.85} $$ and I want to know the residues at its poles. I ...
0
votes
1answer
42 views

How to Set Text Format by User-Defined Function with Input as String

I have simple but annoying problem here. I guess it occurs to many Mathematica users. The thing is that I wish to define a function to format the text in Mathematica. Yet, I don't know whether it is ...
12
votes
4answers
505 views
2
votes
1answer
84 views

Why some variables get substituted and others don't

I was running into some trouble with my math and I whittled it down to this nugget: ...
3
votes
1answer
106 views

Alternatives in pure function construction

When I declare a function f in the following form: f[a|b] := 1 then I can use it like: ...
0
votes
0answers
32 views

Storing a value in array during a for loop

So I have a piece of code below that is used to make a density plot and make the plot into grids, where I then find the center of each grid and store it in the varible called cp. The code for this is ...
4
votes
1answer
59 views

Apply function modification to curried function

This is based on A function that modifies functions - well-defined operation?, a previous question of mine. Lukas Lang's answer of course works very well, but now I encountered the following edge case:...
7
votes
2answers
2k views

Nesting multiple functions of multiple variables

I was wondering how one would go about nesting multiple functions of, say, two variables. The problem comes from trying to implement the Chirikov standard map without using "for" cycles. I found a ...
1
vote
1answer
47 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: ...
1
vote
1answer
43 views

How to pass results of computations to a function definition?

Here is the following code that works, F[{x_,y_,z_}]:={16(y-x), x(45-z)-y, x*y-4z); x = Array[a,3]; F[x] and the answer is, ...
0
votes
1answer
171 views

Automating a large operation by making a function

I would like to automate the following operation. To be transparent I shall put my code into separate chunks and explain the process. Suppose I have the following: ...
0
votes
1answer
53 views

Putting arguments of function automatically

This is a snippet of a code that I have: ...
1
vote
2answers
131 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
52 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
42 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
62 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
43 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 ...
7
votes
1answer
441 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
49 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: ...
9
votes
1answer
371 views

Force evaluation of user-defined function

Consider a function that sorts its arguments based on a function called order ...
2
votes
1answer
79 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 ...
0
votes
1answer
81 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 ...
1
vote
1answer
57 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 ...
39
votes
2answers
2k views

How can I export my learned ClassiferFunction[] and PredictorFunction[]s?

Mathematica 10 provides beautiful high-level machine learning functionality. Sadly, the learned functions once created are rather opaque objects. I need to use them in other projects, so here is my ...
4
votes
2answers
533 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
90 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
91 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
81 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
115 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
45 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
360 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
30 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, ...
3
votes
1answer
311 views

Return unevaluated expression from function

Is there any way (except using upvalues) to make a function that returns it's input Unevaluated? What I mean by that: Take the following example: ...
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
73 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
42 views
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],...

1
2 3 4 5
41