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.
4
votes
2answers
910 views
How to find (numerical) value of a derivative at point?
I have the following function:
f[0, 0] = 0
f[x_, y_] := Exp[-(x^2 + y^2)^(-1)]
How do I find its partial derivatives at any given point, including $(0,0)$? This ...
2
votes
2answers
131 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:
...
9
votes
1answer
307 views
Functional programming and Do loops
I'm writing a Monte Carlo simulation. I'm using a Do loop to create the different simulations, iterating over different ...
12
votes
1answer
143 views
Is it possible to Clear all variables (but not functions)?
I have written a Mathematica script in which I define functions and variables. Here is a vastly simplified example:
...
1
vote
2answers
189 views
Using Functions as Arguments to Function
I am trying to make a function like Norm but defined like so: MyNorm[{x_,y_,z_}]=Sqrt[x^2+y^2+z^2]. Mathematica assumes that x, ...
8
votes
2answers
203 views
Generating a position lookup function for an arbitrary list of integers
In my code, I generate a list of integers called numlist. Here is an example numlist:
...
1
vote
2answers
182 views
Piecewise function with a function as argument
I want to define a piecewise function, which has two arguments, one of which is a function of the other's piecewise argument. I am giving an example
...
1
vote
2answers
102 views
How can define a set of nested parameters
I would like to know how I to define a function with a nested set of parameters (or whatever you would like to call it). For example, how would I get the following function ...
1
vote
1answer
166 views
3
votes
4answers
121 views
Pack Solve results into a vector
I am currently using a really easy function to get the eigenvectors of a corresponding eigenspace:
...
6
votes
3answers
204 views
Where in the documentation can I find a list of function argument types?
Recently, I learned that it is possible to assign "types" to function arguments in the definition of a function. Suppose I have a function stringFun that does some ...
22
votes
6answers
671 views
Convert an expression to a Function
I need a function which can take an expression and return a pure function based on the symbols in the expression. The symbols might have values so must be protected from evaluation. It is probably ...
4
votes
2answers
125 views
Standardizing a coset table via matrix manipulation
Suppose we have a group $G$ and a subgroup $H$. A coset table encodes the permutation representation of $G$ on the right cosets of $H$. When we want to use these coset tables in calculations, it is ...
5
votes
4answers
323 views
Swap two entries in a matrix
Is there a nice, simple script one can use to swap two entires in a matrix? For example, suppose we have the matrix below:
$A=\begin{pmatrix}2 & 4 & 1\\
3 & 1 & 2\\
4 & 3 & 1
...
3
votes
2answers
182 views
Defining a function using Series? [duplicate]
Possible Duplicate:
General::ivar is not a valid variable when plotting - what actually causes this and how to avoid it?
I need to define a function using the output of series, i.e.
...
4
votes
1answer
162 views
Finding mappings between expressions
Suppose we have an expression of the form:
$j=\frac{A\left(t\right)}{B\left(t\right)}=\frac{C\left(s\right)}{D\left(s\right)}$
That is, $j$ can be expressed either as a function of $t$, or as a ...
3
votes
1answer
150 views
Evaluation of self-defined functions
I defined a function that I call disc which I want to minimize later. The function is defined as
...
11
votes
4answers
289 views
Assessing argument type in set delayed function definitions
I'm wondering how to properly assess the type of arguments passed to functions defined with :=. I want my functions to be the most efficient, unambiguous and clear ...
10
votes
2answers
232 views
Proper way to add vertices to an adjacency matrix
I'm looking for a robust way to add vertices to a graph by modifying its AdjacencyMatrix.
Here's what I have so far:
...
2
votes
3answers
566 views
2
votes
3answers
116 views
Function[] argument nesting for operations like Select[]
The following code selects a special element from a list
thelist = {"this", "notthis"};
Select[thelist, (# == "this") &]
What I want is a function which ...
2
votes
2answers
116 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
3answers
180 views
How to Compute Aggregate Best and Worst Cases for a Large Number of Estimates?
I need to aggregate multiple estimations, but I haven't been able to find a built-in function in Mathematica that aggregates multiple probablity estimations (I am specially interested in estimations ...
8
votes
2answers
254 views
Define parameterized function
I would like to be able to define the gain function of a system from its parameters. Specifically, I'd like to define a function that accepts two inputs, call them $b$ and $w$, and returns a function ...
13
votes
2answers
298 views
SetAttributes[f,Flat]: Why the order dependence?
I'm experiencing a strange phenomenon. Here's a (quite artificial) test case:
The following definition work just fine:
...
14
votes
3answers
348 views
Using pure functions in Table
I need a table with the elements made of pure functions and list elements. This is a simplified example:
I need a list as:
...
15
votes
8answers
536 views
How do you check if there are any equal arguments(even sublist) in a list?
I would like to set up a function which has to return True if at least two arguments of a given List are equal.
So if I give {1,4,6,2} to the function it has to ...
4
votes
2answers
150 views
Returning Replacement Rules in a function and using it later on
I would like a function which returns replacement rules as some internal mathematica functions are doing and use the results in other functions.
I could not find any information on that and I'm ...
6
votes
2answers
222 views
Passing unquoted strings (poor man's enumeration)
I would like to be able to pass an unquoted string as a parameter to a Mathematica function [that I am writing] and have it show up without evaluation if the string happens to be defined. Thus I would ...
2
votes
3answers
151 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 ...
12
votes
3answers
272 views
Function that counts the number of arguments of other functions
I have a newbie question: is it possible to write a function that counts the arguments (total and optionals) of a given function? Possibly it should be able to work with built-in and custom functions ...
2
votes
2answers
109 views
How to evaluate this product
I was trying to evaluate this product
$$ \sin (1^\circ) \sin (2^\circ) \sin (3^\circ) ... \sin (88^\circ) \sin (89^\circ) \sin (90^\circ) $$
But I think it got weird results with this ...
28
votes
2answers
593 views
Tiling a square
I wondered if there was a way to automate the process of finding a way to tile a tile into a square.
The idea is to represent the tile with a matrix of 0s for blank space and 1s for filled spaces ...
9
votes
6answers
1k views
Recursive function with if-statement
I am trying to represent the following function definition in Mathematica:
$$\begin{align*}
f(1)&=1 \\ f(2n)&= \begin{cases}f(n) & \text{if}\space n\equiv0\pmod{2} \\ 2f(n) & ...
2
votes
2answers
120 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:
...
5
votes
1answer
346 views
Nesting multiple functions of multiple variables
I was wondering how one would go about nesting multiple functions of, say, two variables. The problem comes from trying to implement the Chirikov standard map without using "for" cycles. I found a ...
9
votes
4answers
260 views
Can a function be made to accept a variable amount of inputs?
I have a function that takes two inputs and processes them for a single output. What I need is one that can take a varying number of inputs. and process them to a single output. Is this possible in ...
8
votes
3answers
158 views
How to make MapAt work with Span?
Span (;;) is very useful, but doesn't work with a lot of functions. Given the following input
...
0
votes
2answers
130 views
Constraining two points, a specified distance apart, to a line
Suppose that I have two points in the xy plane: pt1 and pt2init. pt1 is fixed in space, ...
21
votes
3answers
659 views
Sum over n variables
What is the most painless way to sum over n variables, for example, if the range of summation is $i_1 < i_2 < i_3 < \dots < i_n$, where $n$ is an argument of the function in question?
Is ...
7
votes
1answer
436 views
How to find the smallest root
I have a continuous, differentiable, monotonic, bounded function called F[t]. If t -> Infinity then ...
14
votes
3answers
212 views
What's wrong with this pattern of the form Except[Repeated[…]]?
I'm trying to build a head that recognizes molecules. Here's the code
...
6
votes
1answer
101 views
Property assignment on a graph vertex using PropertyValue does not work inside a function
I created this function:
AddStone[board_Graph, v_, s : white | black | empty] :=
PropertyValue[{board, v}, VertexState] = s
This function should change the ...
4
votes
1answer
202 views
How do I use the result of Solve in a function definition?
I'm trying to adapt the following piece to the part where PowerF is a function of amax.
...
13
votes
3answers
387 views
Is it possible to get the order of inputs when “overloading” an orderless function?
When working with symbolic matrix operations or other objects which don't have commutative multiplication, it would be nice to not have to constantly switch out times for ...
4
votes
3answers
305 views
Integrating with multiple indicator functions
I am trying to calculate an integral involving multiple indicator functions, such as:
$$ h(u,v,w) = -\int_0^1 J^{\prime\prime}(s) (I_{(0,s]}(u) - s)(I_{(0,s]}(v) - s)(I_{(0,s]}(w) - s)\, ...
4
votes
3answers
126 views
Constructing a function with Flat and OneIdentity attribute with the property that otimes[a]:>a
I want to have a function (called otimes) with the following two properties:
it has the attribute OneIdentity and ...
7
votes
3answers
157 views
Generating date ranges
How can I, in one line, generate all the dates with a constant day difference from one date to another?
For example, if I'm interested in dates in the interval staring from 24.4.2012 till 2015 and a ...
10
votes
2answers
363 views
How to plot a barycentric line
I want to plot a barycentric function on an equilateral triangle (ternary plot). For example
f1 = {Abs[Sin[x]], Mod[x, 2], Abs[Cos[x]]};
At the moment I evaluate ...
10
votes
2answers
295 views
Constructing functions aware of the number of output arguments
In Mathematica, you can construct a function f to have different definitions based on its input arguments. For example, ...



