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.

1,651 questions
Filter by
Sorted by
Tagged with
65 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 ...
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 ...
93 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 ...
61 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: ...
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: ...
351 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 ...
79 views

Defining functions from strings

Blank symbol (_) is moved when applying ToExpression to the following string: ...
79 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 ...
120 views

Table and FindRoot of a two-variable interpolated function

I am having difficulty solving for the roots of the following interpolating function: ...
83 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 ...
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 ...
40 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: ...
47 views

Derivative not evaluating when function defined

I have the following code ...
52 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: ...
170 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 ...
31 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?
46 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. ...
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 ...
145 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 ...
290 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 ...
187 views

Efficiently merge lists chronologically without duplicates?

Prepare some dummy data to investigate: ...
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 ...
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] ...
51 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 ...
29 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 ...
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 ...
38 views

Tracking back a variable corresponding to an output

I have a function: ...
46 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 ...
20 views

Error while defining custom matrix function

I'm trying to define a custom matrix Ry with a parameter x, in Mathematica. ...
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 ...
719 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 ...
79 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 ...
30 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. ...
31 views

Define a function when given a graph with points (0,3),(2,5),(10,4),(6,2) [closed]

Define a function when you are given a graph with points (0,3),(2,5),(10,4),(6,2)
101 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 ...
468 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,...
123 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 "...
31 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 ...
78 views

How to use Manipulate in filter design to plot the sum two raised-cosines?

I would like to be able to add a raised cosine to a "standard" raised cosine. With a time delay which I could manipulate (so the shape of the standard cosine function is altered, meaning the function ...
43 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 ...
45 views

How to simplify Log expressions using rules

I have the following expression, ...
76 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, ...
55 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 ...
66 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 ...
52 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 ...
23 views

Redefining the inbuilt function and its derivative [duplicate]

I want to redefine the DiracDelta functions and its derivatives. I am successful at redefining the DiracDelta function but not ...
36 views

Saving DownValues for a function computed in parallel

Is it possible to save DownValues of a function computed using a parallelization routine? I have a rather costly function f I wish to evaluate at a grid and save ...
50 views

Why is this iterative process with matrix calculation so slow?

I am trying something similar to the following code with Ntime as large as 100 or so. Now it's very slow as shown by the Ntime=3 ...
Beside I've found answers to similar questions (e.g. this), I can't adapt them to my case. I am interested in the following sequence of functions $p_{m,n}(t)$, where $m$ and $n$ are integer:  \...