# Tagged Questions

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.

128 views

### Substitute a function's definition for its name

I'm having trouble with a function which is supposed to work on another function. Simplified version: ...
80 views

### How can I adjust the global input variable of a function to the value of a local variable within the function

I am trying to define a function f[l_] that will perform an operation on whatever input variable I use (normally I use l which ...
55 views

### How to define a function deriv[f[x]] such that its output is an unevaluated expression fx=D[f[x],x]?

I want to define a function deriv[f_[x_]] such that when I run deriv[f[x]], the output is an unevaluated expression ...
62 views

### Function to list Collatz sequence doesnt work [duplicate]

I am new to Mathematica and was trying to make a function that lists the Collatz sequence stating with a given number, but I can´t get it to work. Here is my function: ...
182 views

### Defining a derivative on a custom function

I am trying to define a derivative that acts on a custom function, $f$, such that when it acts, it increments one of the arguments of by 1. f is not defined; I just want to use it to keep track of ...
67 views

### Dropping rational coefficients

I have a list of expressions (they all are exact numeric quantities, not containing any variables), some of them have integer or rationals coefficients, or complex coefficients with rational or ...
128 views

### Setting ::usage for variables returned from a function

What is the best way to achieve {v,u} = f[]; (* Returns value and usage description *) v::usage = u; from inside f, i.e., <...
64 views

### Manipulating unevaluated expressions in nested function calls

This is a follow-up to my earlier question: Passing an unevaluated part of an association to a function I'm trying to create a modular dashboard that controls sound volume of an audio system ...
117 views

### Element assignment in matrix function

I have to define a function of two variables that yields a high dimensional matrix, with each entry containing a scalar function, that uses its coordinates in the matrix as input. like this: ...
260 views

### How to get numerical results from HeavisideTheta?

I have defined a table tab = {7.52521, 17.0083, 22.5678, 11.8707, 8.27799} and a function ...
105 views

### Min function for functions f1, f2, [closed]

There are several "min" functions in Mathematica. In the "Numerical" category, there is a "Min" function that works on a numerical list. Then there's MinValue for finding the minimum of a whole ...
149 views

### How can you get the area of a region from an image?

Suppose we have a square of side "L" m, How can I calculate the hatched area, if the corners of the square are centers of circles. It can be generalized to any region? edit: This is the result I ...
342 views

### Is there a GraphicsPrimitiveQ (or a complete list of Heads of graphics primitives)?

For various reasons related to workflow associated with creating figures for journals, I am creating functions that will accept graphics primitives and a set of options and spit out a ...
58 views

### Appending Delayed Evaluation

I have a function that need to be summed over all parameters given in a separate list. f[x_,y_,z_,n_,i_]:= (*Some function*); list={{n1,i1},{n2,i2},...}; I need ...
253 views

### Multiply pure function with scalar

Somtimes I still get lost in the Hold, HoldAll etc. functions of Mathematica. I want to scale a simple PDF function with a previously calculated variable e.g. ...
59 views

### function of a function [closed]

I have the following two functions, 'f' and 's': ...
52 views

### Finding function by constraints

I have the following coefficient finding problem: f[x] := a * Log[b*x + c] + d Constraints: f[0] = 1 f[80] = 0.5 I want to find the coefficients of f that ...
57 views

### Mapping Linear Model Fit Over An Arbitrary Number of sets

I have multiple sets of data, and I want to apply Linear Model Fit sequentially to each set of data. For example, below tstlst contains 3 data sets. Right now I ...
182 views

### How to declare a function as real in order to get rid of Conjugate in front of the expressions?

I have a complicated complex function containing some other ones that are real, f=f(A,B,C,...) ,where A=A(r) and it is real, for ...
76 views

### Plot does not take range with OptionValue and PlotRange option

I am making a function that is to use Show to overlay a few plots of a function. I want the first Plot in ...
70 views

### creation a table from a default module [closed]

I have used of bisection method for finding the root of a function: ...
279 views

### How to write an operator that acts on pure function (to give another pure function)

I would like to write an operator oper that acts on a pure function f with an undetermined number of arguments, with the syntax <...
128 views

### Is there an elegant way of delaying evaluation of A==B` when calling a function that uses this pattern

Suppose I wanted to define a number of functions that accepts expressions of the form: ...
83 views

### Functions becoming undefined when evaluated

I'm so confused I don't even know how to phrase my Question title. My function nextCol works until I use colLength, then ...
22 views

### Protected Tags Error [duplicate]

While trying to run this piece of code: ...
88 views

### How to define $x^n$ where $x=\pm 1$ and $n\in\mathbb{Z}^{+}$?

I do not know how I can define $x^{n}$ in Mathematica, where $x=\pm 1$ and $n=1,2,3,\ldots$. For even values of $n$ we simply have that $x^{n}=1$. While for odd values of $n$ we have that $x^{n}=x$. ...
67 views

### Custom display for constructed functions

In a similar vein to my previous question, is it possible to define a function that displays differently to its default? eg I would really like Binomial[a,b] to be ...
72 views

### Define operator with special characters [duplicate]

I have looked here which describes how to define operators. I was wondering whether there was a way to assign thes operators to special characters? eg Let $\odot:=(a+b)(ab),$ so ...
80 views

### Inverse Superposition

There are 4 tables that, I have written them as bellow: (m, n, s, and r are orthogonal basis. r.r=n.n=m.m=s.s=1, and m.n=n.r=...=0). a's, b's, c's and d's are coefficients and are numeric values. <...
75 views

### Setting constants in a function containing If

I'd like to set the constants in a function that uses If, after it's been defined, but my definitions doesn't seem to stick. Simple example: ...
59 views

### Defining a function with a subscripted head

How can I define a function with subscript? Forexample: f_alpha[x] = 2*x
82 views

### Type declaration for list arguments

How can I make f[n_Integer]=2*n valid for a list of integers? For example: f[nlist_Integer] := 2*nlist[[1]] does not work ...
439 views

### How to check the style and number of arguments like the built-in functions?

Given that I have a function sqrt[x] that I must check the style and number of argument x. I can do like this: ...
152 views

### How do I make a definition/function/method as I would in Java/MATLAB/Python

I've been trying to figure this out for a few hours now and it's driving me nuts. I am trying to confirm that, after transforming a Schrodinger equation, that the new wavefunctions satisfy the new ...
55 views

### Insert several rows and problem with Return

I wanted to write myself a function that makes it possible to Insert several rows into one list. ...
119 views

### How to Implement a “Function Object” suitable for NDSolve and Finite Element Method?

I have a bunch of methods that shoud return an expression that behave like a function, i.e. an expression that, when supplied with suitable arguments, evaluate to something. A simple ...
80 views

### Working with a two-variable function with one input fixed

Here's what I know how to do: f[x_] := x^2 - 4 x + 4 Ordering[f /@ {1, 2, 3}] This will evaluate f at each point and rank their sizes. Here's what I really have:...
361 views

This function finds n given the nth prime: findPrime[n_] := If[PrimeQ[n], i = 1; While[Prime[i] < n, i = i + 1]; i, False]; This works: ...
95 views

### How to make a twice-differentiable function that approximates some data?

I have some time series data that I would like to approximate with a twice-differentiable function. Each time series has ~10,000 datapoints, so I definitely do not want a function that passes through ...
49 views

### Why this isn't a valid argument? [duplicate]

I am having truble understanding why F1 produces an error, since both time and velocity are the same kind of object: ...
68 views

### Change input parameter order in a function

I'm a beginner in Mathematica programming and I'm trying to understand how input parameters work in Mathematica's function. I encountered a problem with the sequence/order of the input parameters of ...
181 views

### Defining a 2-variable function over voronoi diagram

I am new to Mathematica & I am facing a problem as follows: I have created a Voronoi diagram and now I want to assign to each region, a value, i.e., I want to extend this Voronoi diagram to form a ...
51 views

### Strange behavior when defining a symbol/function pointwise

I am well aware of the fact that floating point number have finite precision, so one needs to be careful when comparing them. Still, I find it disturbing/surprising that the following input into ...
84 views

### Orderless storage of tabulated function values

I would like to elaborate on my previous question Function of arguments given in non-fixed order and a relevant related one Best practice of passing a large number of parameters to functions I find ...
49 views

### Constructing a function for expanding general $n$ products

I have the following quantum mechanically motivated product: $\langle0\vert(A_1b_1 + A_2b_2 + A_3b_3)(B_1b_1 + B_2b_2 + B_3b_3)(C_1b_1 + C_2b_2 + C_3b_3)$, where $b_i$ is an annihilation operator ...
82 views

### Construct a function whose definition depends on the values of its arguments

I have to evaluate the components of a 6x6 matrix $S$. This matrix depends upon the semi-axes of an ellipsoid $a1$, $a2$ and $a3$. For various specific cases (sphere, prolate spheroid, oblate ...
108 views

### How to force evaluation on the right of an @ operator?

Is there a way to force evaluation on the right before the Prefix operator (@) without using parentheses? I came across this question when I was working with the ...
142 views

### Problem with the output of a function I program

(This is the function that I programmed) Zm2[Z_, nk_] := (zm2 = 0; For[i = 0, i < Length[Z], i++, zm2 += nk[[i]] *Z[[i]]* Z[[i]];]; Return[zm2];); (...