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.

learn more… | top users | synonyms

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

Table of references [duplicate]

I have a list of variables (say a, b, c, d, e) that I want to assign in a single command. {a,b,c,d,e} = {1,2,3,4,5} would ...
2
votes
1answer
147 views

How in Mathematica, would I define a function that takes arguments much like one would in an object orientated language

I would know how to write a function in object orientated language, just I don't know how to do this in mathematica, in an OOP I would define a function like this: ...
2
votes
2answers
178 views

Understanding `NestList` with multiple functions

General question For a function f[n, a], where a is a list and n is a whole number, what is ...
2
votes
1answer
61 views

Searching for symbol except within subexpressions with a particular Head

I would like to write a searcher like FreeQ that looks for a Symbol (or Head) in an ...
2
votes
2answers
166 views

How to get `Series` to recognize user-defined function has pole

Edit for clarity: How does Mathematica's function Series know that Gamma[x] has a pole at ...
2
votes
1answer
172 views

Passing function as argument

I've been mucking around with passing functions as arguments to other functions and via trial and error seem to have something that works. I was wondering if someone could have a quick look at some ...
2
votes
1answer
127 views

How to constrain the range of a plot of a function to satisfy an inequality?

Given the function f[x_] := x^2, how can I plot f[x] over the range where f[x] >= 10 and <...
2
votes
2answers
281 views

Find partial derivatives when the number of variables is unknown

The idea is that I have a defined function of $n$ variables. I want to find out $n$ and get partial derivation for each of variables, Suppose you have a function ...
2
votes
1answer
233 views

Writing NDSolve-like functions

I've been using Mathematica for a while now, and there are multiple common tasks that I end up doing. I'd like to learn how to convert them into functions so that I can store them in some file and ...
2
votes
2answers
131 views

Putting a matrix inside function

I want to fit a function to some data and inside the function there's a list here's my data ...
2
votes
2answers
402 views
2
votes
2answers
95 views

Recursion: How can i program this expression?

i have the following expression: Vt[EA_, V0_, Cm_, B_] := EA + (V0 - Cm)*B For EA and Cm ...
2
votes
2answers
97 views

Function where variable is integration bound

Lets say I have a function of the form: $f(T) = T^4 \int_0^{1/T} \frac{x^3 dx}{e^x-1}$ This is an example of the situation I am describing not a unique problem. I want to define it as a numerical ...
2
votes
1answer
103 views

Why must I specify the Global context for a symbol in a private package?

I have written two versions of the function below in a package. When I load the package and call the function, Why does the first version where the variable s has no explicit Context return the long ...
2
votes
1answer
68 views

How can an argument of the form f[t] be injected into the RHS of a function definition [duplicate]

This is what I want, for an arbitrary function x This is what I have done: ...
2
votes
1answer
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:...
2
votes
3answers
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 ...
2
votes
1answer
75 views

Is there a shorthand for Optional with Condition?

I have a recursive function that does some work to an object for a repeatedamount of times. ...
2
votes
1answer
1k views

Inverse gradient operator

I found a nice paper about inverse vector operators here. I have successfully implemented a Mathematica function for most of them, however I can't figure out how to do inverse gradient (page 7 in the ...
2
votes
2answers
212 views

Returning the 3-dimensional vector from a skew symmetric matrix

I'm trying to write a function that takes in a skew symmetric matrix and returns the corresponding vector. When I write the following code, it works when I leave it as variables, but it does not work ...
2
votes
1answer
74 views

Unprotect fails the first time, works on second pass [duplicate]

I am redefining some of the standard math functions. I know this is dangerous, so I am trying to be extra careful. (For instance, in the redefinitions, I make sure to only match a custom head) The ...
2
votes
1answer
828 views

Why is either Listable or HoldFirst not working?

Starting with a fresh kernel, I evaluate the following: ...
2
votes
1answer
112 views

Having variables appear aqua in user defined function [duplicate]

In many of the inbuilt mathematica function, variables appear aqua like in: However, when creating your own function, variables no longer have that green coloring and are instead colored like an ...
2
votes
1answer
216 views

Requiring NumericQ in Pure Function

Potential duplicate, but doesn't seem to solve my problem: Using patterns in pure functions I have a function that returns an InterpolatingFunction, and it works ...
2
votes
2answers
576 views

Recursive formula involving a piecewise function

I am trying to construct a recursion, g[t], where g[t] = a[t] if g[t-1] = 1 ...
2
votes
2answers
315 views

Working around behaviour of EdgeRenderingFunction

One can make graphs GraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 4 -> 5, 5 -> 1, 1 -> 1, 5 -> 5}] and one can generalize the input such that one ...
2
votes
1answer
49 views

Passing a list to a nested vector function

In order to apply a newton-rhapson algorithm to solve a set of nonlinear vector equations such as these, f[x_, y_] = {x^2 - 3*y + 6, (y + 1)^2 - x - 33} I need ...
2
votes
1answer
46 views

combine two definitions into one [closed]

Suppose I have two definitions of a function such as ...
2
votes
1answer
371 views

Defining solutions to FindRoot as a function of parameters in Mathematica

This works: f[a_] := x /. FindRoot[x^2 - a == 0, {x, 1}] f[3] (* 1.73205 *) I need this to work, but it doesn't: ...
2
votes
3answers
96 views

How to test a condition for a list and output all the expression that is true?

Suppose that I have a list lis={x-y,x+y,x*y}; and a function f[a_,b_]:=#/.{x->a,y->b}& I want to output all the ...
2
votes
1answer
64 views

What are the applications of using functions whose heads are also functions?

I noticed that it is possible to construct something like f[x][y]. Displaying this in TreeForm indicates that this expression ...
2
votes
1answer
85 views

How do I tweak the input assistant to use string completion on my own functions? [duplicate]

I would like to be able to use Mathematica's string completion feature for subvalues of my own functions. I tend to go for functions that follow the pattern ...
2
votes
2answers
92 views

Adding a tree to a list of trees within a loop [duplicate]

I'm trying to write a function which for a list of trees checks if a given tree is isomorphic with any of the listed, and if not - adds it to the list. I tried to use both ...
2
votes
1answer
99 views

Generating list of functions from list of expressions

I know how to create a function from concrete expression like Function[{x, y}, x^2 + y^2] But what if I have a list of expressions list1 and I know the set of ...
2
votes
1answer
721 views

Defining Piecewise Functions [duplicate]

I'm having trouble defining piecewise functions. What I have so far is a function that outputs something in a suitable format for Piecewise: ...
2
votes
1answer
154 views

How to define a function of z[bar], etc

Using Displaying index as subscript on output: e.g. C[i] -> C_i with Notation[...] or Interpretation[..]? I have often ended up wanting to define functions of annotated variables to better match my ...
2
votes
2answers
1k views

Composing two functions in Mathematica [duplicate]

Possible Duplicate: Composition of mappings not working as expected I am new to Mathematica and I am having trouble defining a certain composition of functions. Let ...
2
votes
1answer
276 views

How to override `?NumericQ`

I have a function myFunc which I is to be displayed cleanly if arguments are symbolic, but which can also be numerically evaluated. I do this by defining a ...
2
votes
1answer
219 views

How do I determine if there's an arithmetic sequence within a list? [duplicate]

Possible Duplicate: find subsequences of constant increase Given an arbitrarily long list of integers (let's say they are sorted), how would one determine if any 3 (or more) of those integers ...
2
votes
1answer
121 views

How to properly define this function of function

I encountered real problem at first, and here is the toy example variable argument stored some expression that is generated from other parts of the program. I ...
2
votes
1answer
53 views

Defining function [duplicate]

ver1 = 2 x verf[x_] := ver1 verf[3] Result : 2 x Expected Result : 6 In the above code ...
2
votes
1answer
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 ...
2
votes
1answer
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 ...
2
votes
1answer
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 ...
2
votes
1answer
544 views

What is the meaning of two square brackets in function definition? [duplicate]

I came along the following function definition f[a_, b_, c_][r_] = ... with some function on the right hand side. Is this equivalent to ...
2
votes
1answer
284 views

How to make a function from body with variable number of arguments?

Suppose I have an UNKNOWN function, which generates formulas with given number of x[i]. ...
2
votes
1answer
45 views

Linear function on strings using UpValues

I have two functions Sup and Sdown that take a string of letters with allowed characters ...
2
votes
2answers
125 views

How to make functions from datasets

I have a csv that encodes the results of plugging certain parameters (say, A and B) into certain functions (say, ...