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
6
votes
1answer
55 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
67 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
28 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
703 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
79 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
33 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
62 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
87 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
46 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
314 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
77 views

Defining functions from strings

Blank symbol (_) is moved when applying ToExpression to the following string: ...
3
votes
1answer
73 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
110 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
77 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
23 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
43 views

Derivative not evaluating when function defined

I have the following code ...
2
votes
1answer
50 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
168 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
29 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
80 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
142 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
261 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
33 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
44 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
21 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
30 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
36 views

Tracking back a variable corresponding to an output

I have a function: ...
0
votes
1answer
45 views

Preventing an output of a function from being assigned a value

Say I have a function Example[n_Integer]:=n{x,y,z} Example@4 {4 x, 4 y, 4 z} Now, let us assign some values to ...
0
votes
0answers
20 views

Error while defining custom matrix function

I'm trying to define a custom matrix Ry with a parameter x, in Mathematica. ...
1
vote
0answers
47 views

Why don't these function definitions work? [closed]

picked up Mathematica (transitioning from Python) a couple of days ago so forgive me for the newbie question. I'm trying to create a function which takes in a list of numbers and returns a list of the ...
14
votes
2answers
711 views

Flatten not working

I am trying to modify some code proposed here Part assignment is not a symbol and I cannot manage to make Flatten work. I write ...
1
vote
1answer
73 views

How to pass lists as arguments in NMinimize or FindMinimum?

The following code runs in Mathematica 12. But, I have two problems that I would like to solve: (1) How to pass a list as an argument to the function g in such a way that it can be used seamlessly ...
2
votes
1answer
25 views

CloudObject when defining functions - how to remove?

I'm an absolute idiot when it comes to Mathematica - I only use it for really basic things (because we use it as a graphic calculator in my high school class), so formatting will be less than ideal. ...
-2
votes
1answer
30 views
4
votes
2answers
90 views

Constant Distribution

As far as I know, Mathematica lacks a definition for a probability distribution representing a constant random variable. Is this assertion correct? Is there a problem in making such a distribution ...
21
votes
2answers
431 views

Custom atomic expressions - modern tutorial

Atomic but sophisticated expressions are all around for a long time: Graph SparseArray. More are coming witch each new release,...
3
votes
1answer
99 views

Exponential generating function

I need to find the $m^\text{th}$ term for the following expression: $$ \left.\frac{\partial^m}{\partial t^m}e^{a t^2}\right|_{t=0}$$ I computed first few terms and used mathematica "...
1
vote
0answers
29 views

Make a function invariant under a permutation of the arguments

The output of my current notebook contains expressions that look as follows (V[{k,q},{s,t}] + V[{-k, -q}, {t,s}]) In my specific application these two functions ...
1
vote
1answer
42 views

Issues with negative sign in front of rules for Logarithm simplification

I declare a very simple rule. rule = -x_*Log[a_] :> x*Log[1/a] Now I give two expressions, -x Log[d] /. rule which ...
1
vote
0answers
45 views

How to simplify Log expressions using rules

I have the following expression, ...
1
vote
1answer
54 views

Function returning a pattern with condition - how to prevent condition to evaluate prematurely?

I figured it would be convenient to have a function that returns a pattern, that match equally nested brackets, of the specified type. Such a pattern is easy to create, but I get some error messages, ...
0
votes
1answer
50 views

Definition of complex conjugate?

I came across the following way of defining complex conjugate in mathematica [a]: SuperStar[y_] := y /. Complex[u_, v_] -> Complex[u, -v] I am able to ...
2
votes
1answer
64 views

Defining a function that has no return value

How can I define a function with no return value. For example, the Notation function from the Notation package seems to have no return value; I am looking to do the same thing for some of my custom ...
0
votes
1answer
43 views

Why is this NDSolveValue function remembering past inputs?

I have been attempting to generate a function that uses NDSolveValue to return the value of a solution to a system of ODE's when an event condition is triggered, as a function of the initial ...