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
2
votes
1answer
38 views

Operate on functions with arbitrarily many arguments

Is it possible to define a function that can operate on another function with arbitrarily many arguments? For example, I want to do error propagation using partial derivatives. It is not clear to me ...
6
votes
2answers
135 views

Collect data points in a list into weekly groups?

Consider data of a format such as ...
0
votes
0answers
49 views

Function Without Argument [on hold]

Can I define a function without having to give it some arguments? The reason I want to do this is that I don't want to pass on some global variables as arguments through every function I define but I ...
-1
votes
0answers
65 views

Module is taking too much of time to produce its results

I have written a function f using Module. What it does is take 6 inputs and output a plot. The module seems perfectly fine. I ...
1
vote
2answers
43 views

Restrictions as string to expression in region plots

I'm trying to build a function that generate a string of restrictons to pass on to a region plot with ToExpression, but I think it fails to pass the plot variables. ...
0
votes
1answer
53 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: ...
3
votes
2answers
123 views

Automatically bound histogram regions?

Given a histogram of some data, such as e.g. in the following sample https://www.codepile.net/pile/NLlNgP60 ...
3
votes
1answer
51 views

Implementing Simpson's rule with two variables

For one of my lab project I need to integrate a given function (in this example, f1, using Simpson's ruls. When only one variable ...
4
votes
1answer
30 views

Computing Higher Order Tensor of Variable Rank

The following code takes a vector x of variable length, computes the outer product of the vector with itself to form the matrix $\rho$ of dimension $2^n \times 2^n$....
0
votes
1answer
34 views

Functions with Variable Numbers of Arguments: Outer Vector Product

I am trying to write a function that takes a column vector of variable dimension as an input and returns the outer product matrix as an output. What I have tried: ...
1
vote
1answer
40 views

Higher Order Tensor of Variable Rank

I would like to write a function, that matricizes a higher order tensor according to the following rule: Let $\mathcal{A} \in \mathbb{C}^{I_{1} \times I_{2} \times \ldots \times I_{N}}$ be a tensor ...
0
votes
0answers
44 views

Function works outside For loop but not inside, and loop fails spectacularly

I'm building two lists, each to carry a different representation of the same set of objects. One list, list2, is constructed first; then the second list, ...
0
votes
1answer
40 views

WriteLine[] not working once put into a function

I wrote a function that takes two strings, an integer, and an OutputStream, it's supposed to write to. The function is: ...
1
vote
0answers
34 views

How to convert output from Reduce into a piecewise function?

Reduce often provides a much fuller solution than Solve. But it's always in the form of a true statement rather than functions ...
1
vote
0answers
26 views

How to measure the Euclidean distance between each evaluation point and the closest reference point in a 2-D problem? [closed]

I would like to measure the euclidean distance between each evaluation point and the closest reference point in a 2-D problem. Attached my reference and evaluation points to have a look at the inputs....
2
votes
1answer
84 views

How to compile or speed up a function with eigensystem?

I have defined two functions as following: ...
3
votes
2answers
86 views

Function with string explanation for its arguments with equal signs [duplicate]

I want to write a function using string as explanation for its arguments so that the function becomes intuitive for new users. For example, I want to write a function to compute BMI (just for ...
6
votes
1answer
57 views

How to obtain the function of a plotted Bezier curve?

I have some control points and I could just plot the Bezier curve, but I also need to have the function! How can I get the exact function of the plotted Bezier curve?
1
vote
2answers
71 views

Understanding how to loop over different variables in Mathematica

I'm using Mathematica to generate some data, and I'm having some difficulty understanding how my intuition from "regular programming" should transfer over. The code that I'm writing does the following:...
0
votes
1answer
33 views

Defining a function that modifies a list [closed]

I have the a list A and I want to define a function f that takes out the $i$-th element from the list ...
4
votes
3answers
716 views

Function that detects repetitions

I have a large list of 2-tuples and I need a function that lists first values that have at least one repeated second value. Small example: ...
0
votes
2answers
107 views

Specifying that function argument is positive

Struggling with something basic. Suppose when defining f[x_] the outcome depends on Sign[x]. When calling this function, how do I tell Mathematica the sign of the argument? My attempt: ...
0
votes
2answers
38 views

Test if function of multiple variables is positive or negative given variable constraints

I have a function of multiple variables (5 to be exact). I would like to know if this function is positive or negative given certain constraints on each of the 5 variables. Here is a simplified ...
3
votes
1answer
64 views

elegant definition of piecewise linear functions (spline)

As far as I understand, the Spline object is the result of some approximation or interpolation, it is not for directly defining functions. That's a pity, as that ...
8
votes
1answer
2k views

What is -(-2,3,4)?

I was trying to define a function f such that, when its second argument is negative, we have $$ f(a,b,c,d,\dots,n)=f(a,-b,-c,-d,\dots,-n) $$ i.e., we reverse the ...
4
votes
1answer
91 views

Wrong Output in self defined Quaternionic Multiplication

I tried to define quaternionic multiplication in terms of pairs of complex numbers where I identify $\mathbb{C}^2$ with $\mathbb{H}$ via $(z,w)\mapsto z+jw$. Consequently, I used the multiplication ...
0
votes
0answers
59 views

How to list all the possible functions of given structure?

I can run this command : Tuples[{ Tuples[{x, y, z}, 2], {a, b, c}}] to list all combinations that looks like: ...
0
votes
0answers
48 views

Iterative loop with many steps

I want to automate the following code, let me begin by explaining the code first. This code, for representation, is divided into 3 parts. The first is: ...
3
votes
3answers
328 views

How do pure functions differ from functions defined with SetDelayed?

Why is it that f[{{a_, b_}, {c_, d_}}] := (a z + b)/(c z + d) will return (2 + z)/(4 + 3 z) on evaluating ...
1
vote
1answer
78 views

Defining functions from strings

Blank symbol (_) is moved when applying ToExpression to the following string: ...
3
votes
1answer
76 views

Generating all connected graphs from a set of n-valent vertices?

I would like to have a function generateConnected[list_] that, given a set of vertices with pre-defined valence (number of outgoing edges) generates all possible ...
0
votes
1answer
112 views

Table and FindRoot of a two-variable interpolated function

I am having difficulty solving for the roots of the following interpolating function: ...
2
votes
2answers
80 views

How to make a contextual variable?

I have a question that would be trivial in OOP, but I am a newbie to programming in Mathematica, so I'm wondering how to deal with it. Basically, I want to create a package which basically involves a ...
0
votes
0answers
24 views

Creating a function in which certain conditions exist

I am trying to create a function for which it is known that certain conditions exist on the argument. I want this to be a simplified version of the function. For example, if I wanted to create a ...
0
votes
0answers
37 views

Piecewise function to include SawtoothWave function

I am trying to write a Piecewise function that includes the SawtoothWave function. Can someone indicate how to do this, or if it is possible within mathematica? The piecewise code is here: ...
0
votes
1answer
44 views

Derivative not evaluating when function defined

I have the following code ...
2
votes
1answer
51 views

How to write down a probabilistic function in Wolfram Language?

How does one write a Wolfram function which has a 25% chance of returning 1, a 50% chance of returning 2, and a 25% chance of returning 3? Here is how the data structure might look like: ...
4
votes
3answers
169 views

Finding the index of an element to be inserted in a sorted list

I have a sorted list with no duplicates: L = {1, 2, 5, 7, 8} Given an integer n, I want to find the index of ...
2
votes
1answer
30 views

Setting default function values for particular option values

I have a function with some optional arguments. How do I assign a value for the function when one of the optional arguments takes a particular value, regardless of any other argument values?
1
vote
2answers
42 views

How to define a function to be used in a loop?

I have written following piece of codes which is a part of very larger program. ...
2
votes
1answer
82 views

Basic question regarding returning values from user-defined functions [closed]

I'm new to Mathematica today. I would like to write a function that will implement the following pseudocode: f[x_]:= Do something return y I have searched ...
3
votes
2answers
143 views

Function apply to three dimensions list

I defined a function f[x_, y_] := {x - y, x + y} and I have a list d1 = {{1, 2}, {3, 4}, {5, 6}}; I know how to input ...
7
votes
5answers
271 views

How to generate all commutative pairings of list elements?

Given a list with an even number of elements, e.g. list = RandomSample[Array[e, 20]]; how can one generate a list of all different commutative pairings of the ...
10
votes
4answers
184 views

Efficiently merge lists chronologically without duplicates?

Prepare some dummy data to investigate: ...
1
vote
1answer
36 views

Defining a new function to evaluate a previously defined function at specified parameter set, using fewer inputs? [closed]

I have a function in three variables: f[var1_,var2_,var3_]:=expression[var1,var2,var3]; I want to reduce this to g[var3] and ...
2
votes
1answer
36 views

Construction of symmetric function / matching function argument patterns

[Edited for clarification after comment] Suppose that the function f is defined as the linear combination of several translated/reflected functions starting from the primitive f0[x,y,z] ...
2
votes
1answer
47 views

Define a function with specific permutation properties

I want to define a function evaluate[f_[x__]] which acts on an arbitrary function f[a,b,c,d]. The function ...
0
votes
0answers
22 views

Assign a Derivate to a new fuction variable

I'm having a new problem. I'm trying to create a new function from a Derivate of another function, but i'm can't getting it. Someone could help me? I'm thinking that is something in the syntax of the ...
0
votes
1answer
32 views

Constructing sequence of function with elements depending on the previous one / recursion

Starting from a function $\theta0[x\_ , y\_ , z\_ ]$, the terms $\varphi[x\_ , y\_ , z\_ ]$ constitutes a sequence of functions that is constructed as follows: Order 1 (one function and its ...
0
votes
1answer
38 views

Tracking back a variable corresponding to an output

I have a function: ...