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
3answers
136 views

Map several functions in one routine

I have several functions, let's assume they are: func1[x_]=x; func2[x_]=3*x-5; func3[x_]=0.1*x^2; and a lot more like these. For each and every one of these I ...
2
votes
3answers
1k views

Passing a matrix as a function argument

I am trying to do the following: ...
2
votes
3answers
130 views

How to generate a series of bisection points of a given line segment?

I want to get the coordinates of the bisection points for a given line segment to a specified resolution. For example, when the line is given by {0,0} and {1,0}, the output coordinates should be ...
2
votes
2answers
94 views

Rising Recursion Relationships

Lets say I want to compute the following function in mathematica: $G[n,k]=G[n+1,k-1] + G[n+2,k-2]$ where I know that $G[n,0]=n$ and $G[n,1]=n^2$. So, for example, $G[3,2]=G[4,1]+G[5,0]=4^2+5$ or, ...
2
votes
2answers
184 views

Hiding certain user-defined functions in front-end autocompletion

I have written an elaborate code that contains a collection of functions for the user and a bunch of auxiliary functions whose existence I would like to hide away from the user. I've written my code ...
2
votes
3answers
261 views

How do I construct a pure function to extract data fields from records that are strings?

How can I get from data segment format to the final segment format with a pure function? The data fields are fixed length. There are no separators between the fields. a) list ...
2
votes
1answer
76 views

Is it possible to use a mathematical expression as function name?

This might seem as a silly question, but is it feasible to use a mathematical expression as the name of a function? For example, I'm studying the cross section of Compton scattering and there is a ...
2
votes
2answers
142 views

Is it possible to use PropertyValue to modify properties of Graph objects in a list?

This post can be seen as a follow up to Property assignment on a graph vertex using PropertyValue does not work inside a function. I have defined a function: ...
2
votes
2answers
150 views

Defining a function that returns “undefined” if its value is outside of a specific range

I want to define a function f(x) which: $f(x)=x^3 +10x+ 5$ if $f(x) >0$ $f(x)=Undefined$ if $f(x) <0$ I have a idea: ...
2
votes
3answers
366 views

Generating pairs of additive and multiplicative factors for integers

Given an integer $n$, I want to get two lists: a) the set of pairs of the divsors $a,b$ into exactly two factors $n=a\cdot b$, b) the set of pairs $a,b$ of two summands $n=a+b$. The code I ...
2
votes
2answers
94 views
2
votes
2answers
89 views

bulk initialization of associative array/hash implemented with function pattern matching?

I see that we can do associative arrays in Mathematica using functions that have implicit pattern arguments, as in ...
2
votes
1answer
80 views

Map and Scan ignore HoldFirst

I am trying to write a simple function that takes a list of data and outputs it to a file. I'd like the name of the file to be the same as the variable that holds the list. It seems that giving a ...
2
votes
3answers
187 views

Defining a function to determine when convergence is guaranteed

I'm investigating how many iterations are needed for a particular orbit to reach a fixed point of a function. Since I have many functions to test, I want to define a function in Mathematica that will ...
2
votes
3answers
189 views

Ways to change an explicit function into a pure function

I'm trying to use FixedPoint to solve a transcendental equations, but the first argument of the FixedPoint should be a pure ...
2
votes
1answer
96 views

Area between Contours in ContourPlot

I feel slightly foolish for asking this because I am so close, but I'm having trouble, so I will anyway. I asked this question two days ago regarding finding the lengths of contours. Now, I'd like to ...
2
votes
1answer
78 views

How to Override the Head of a Symbol

I was wondering if it is possible to override the head of symbols/operators. As a motivating example if I run: Then Ket will be returned. But lets say I want Bob to be returned instead of Ket. Is ...
2
votes
1answer
79 views

Need to run evaluation 2 times

Why does this only work after running the evaluation 2 times? ...
2
votes
1answer
184 views

Can my permutations function be defined using iteration?

I have two functions, tuples and perm. They are similar. ...
2
votes
1answer
143 views

Rookie mistake in defining a function with Modules?

I can't figure out what's wrong with this piece of code. I'm trying to define a function that counts the occurrences of x, y and ...
2
votes
1answer
109 views

Specifying form in MemberQ

This seems like a very simple question, the answer to which should be obvious to me. So I won't be offended if this question is closed. But I'm having trouble figuring out the answer. I would ...
2
votes
2answers
143 views

Constraining a random function

This question is a follow-up from here. I have a function that generates a list of correlations between some random variables: ...
2
votes
1answer
87 views

Graphics Function Definition Style (Using SubValues vs. DownValues)

I am going through some of the items in "Modern Differential Geometry of Curves and Surfaces with Mathematica, Third Edition". An example of the style used by these authors is: ...
2
votes
2answers
74 views

`PrimeNu` counting function

Building on this question, what is the most efficient counting function for distinct prime factors? It would obviously be more efficient if Prime and ...
2
votes
2answers
374 views

Q-Function representation in Mathematica

I observed that there is no Q-function representation in Mathematica. The definition of Q-Function is: \begin{align} Q(x) &= \frac{1}{\sqrt{2\pi}} \int_x^\infty e^{-\frac{u^2}{2}}du \\ ...
2
votes
2answers
193 views

Writing a function that returns a (usable) function

I am trying to create a function that returns Arnold's Cat Map of size n iterated k times. I can get something out of the Function command, but I can't figure out ...
2
votes
2answers
202 views
2
votes
2answers
124 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
2answers
221 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
1answer
94 views

How can I define a function taking two distinguishable sets of options?

It commonly happens that one wants to define some function foo which in turn calls some other function (e.g., Plot) that can ...
2
votes
2answers
97 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
175 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
2answers
181 views

Algorithm for parts integration

Sorry if this is a duplicate, I've searched how to do this to no avail. What I'd like to do is a function that integrates by parts $n$ times, i.e $$ \int u(x) v(x) dx = u ...
2
votes
1answer
90 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
1answer
146 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
163 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 ...
2
votes
1answer
73 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
119 views

Implementing a For (?) or series or loop (?) for individual results for every x to n

I'm working on improving a modeling formula and have spreadsheets worth of data to use, but my work so far has been quite tedious. I'm essentially pulling 20 rows of data from each separate sheet of a ...
2
votes
1answer
183 views

Defining a function that handles Dynamic arguments similar to Built-ins

Firstly please note that I'm using simply Dynamic behavior to illustrate my question, I'm not asking how to move a Disk or make ...
2
votes
0answers
78 views

Function that assigns properties [duplicate]

I want to create a function that creates and assigns properties to a symbol. In theory this would behave similarly to the NonzeroValues property of ...
2
votes
0answers
31 views

Detecting a more general pattern [duplicate]

I need a function that, given 2 patterns, determines if the first pattern is more general than the second (i.e. that any expression successfully matched by the second, will be successfully matched by ...
2
votes
0answers
112 views

correct usage of ParallelTable

I am trying to parallelize my script. Here is a MWE of how I have done it: ...
2
votes
0answers
77 views
2
votes
0answers
86 views

How can this function's options be used in different places?

I wrote this function to make a ListPlot where the points are colored by a third argument. ...
2
votes
1answer
125 views

Difference between function definitions [duplicate]

Possible Duplicate: Functions vs. patterns I thought about describing the context in which I faced this problem, but I figured it is general enough and clear enough to pose it as it is. ...
2
votes
0answers
289 views

Generating a function which outputs possible chemical reactions

I want to make a list of chemical reactions and I write them down in a $\require{mhchem}\LaTeX$ format. They are of the following form $$NA_n^i+MB_m^j \rightarrow \hat NA_{\hat n}^{\hat i}+\hat ...
1
vote
3answers
351 views

Better solution than returning a list of 3 values?

I have a function (using SetDelayed) that currently returns 3 values in a list. Later on I use the result of this list along with ...
1
vote
3answers
137 views

professionalize/optimize my code that calls a function

I have the following construction, which defines a function that I subsequently call in a loop multiple times. I use this very often, but I have never looked into if there is a more professional way ...
1
vote
2answers
138 views

Using mathematical notation

Is it possible to write this function in mathematica exactly as shown, and then run the expression on a dataset? Please note I know that there are several other ways to do this. I am only ...
1
vote
4answers
277 views

Recurrence relation in a table

I am trying to generate a list of x-values for a function using a module, where my x-value must increase by 'a' if the term ...