# 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.

286 views

### Returning all positions for all different occurences of elements in a list

Is there way to construct oneliner as pure function(s), so that I enter mylist only on one place - on the end of line. And that function return the same result as ...
151 views

### How to save the results in an identical Excel file (.xls) in each iteration of a Do loop

Assume the following code (Below code is just an example to clearly illustrate my problem): ...
331 views

### Change input variable in a function [duplicate]

I'd like to write a function, that would take a matrix as an input parameter and would change it by multiplying one of its rows by a factor. I try to do it in the following way: ...
27 views

### Minimizing roots of a transcendental equations [duplicate]

I'm trying to use the solution of FindRoot with parameters for further calculations. Annoyingly enough it always gives me trouble with replacing the parameters. As an example I'm attaching a simple ...
420 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 ...
468 views

### Plot of a periodic triangular wave

I'm trying to graph the zig-zag function at the top of this page: http://www.math.ubc.ca/~feldman/m321/nondiffble.pdf I have a little bit of experience with Mathematica but not a ton. Any suggestions?...
255 views

### Find lengths of contours in a ContourPlot

I am trying to find the lengths of different contours in the following plot: It is a complicated piecewise function evaluated on the unit disk. I am hoping there is an easy, generalized way to ...
493 views

### A problem with functions and Infinite expression 1/0 encountering

Following code (function) makes integrals and then replace f[x] with Cos functions and calculate the definite parametric ...
138 views

### A problem with set values

The following code is just an example to clearly explain my problem. Assume that : ...
136 views

### Initialize table in a Module but Break if criteria not met

I am initializing a table inside a function as follows: f[a1_, a2_, a3_] := Module[{RM = Table[a1+a2+a3+i1, {i1, 1, 10}]}, Plus@@RM] I am calling the function <...
95 views

### How to produce functions [closed]

I want to produce n functions. For example, assume that by giving n=3, 3 definite integrals will be created, like the following: ...
158 views

### iterative programming

i have 3 equations with 3 variables and two constants(to be substituted repeatedly). the value of the variables we got by applying nsolve on the system of 3 equations assuming some initial value for ...
193 views

### Getting Arg[z] to go from $0$ to $2\pi$

I'm defining branch cut functions, and I'm using $\arg(z)$ as a building block. So I just spent an hour at the whiteboard assuming that $\arg(z)$ goes from $0$ to $2\pi$, and then I implement the code,...
93 views

### How to define a function $f(x)$ such that $f(1.5)=1.5$, $f(1.)=1$, $f(0.)=0$, etc.?

How to define a function $f(x)$ such that $f(1.5)=1.5$, $f(1.)=1$, $f(0.)=0$, etc.? Namely, if $x$ is an integer with a decimal point, $f(x)$ returns the integer only, otherwise returns $x$. This ...
95 views

### Determining whether or not an expression is an integer

I'd like to define a function that controls if a certain number is an integer, rational, algebraic and so far. First, I tried generating a list of those numbers: ...
117 views

### A question about two ways to use Default

Usually we define a function with default values by the syntax x_:default, but there is another technique to do this by registering a global default value with <...
1k views

### Constraining function found by NDSolve to stay positive

I am trying to constrain my variables in NDSolve so that they stay positive for the integration interval. Is is possible to do that? Using Assumptions as in ...
157 views

88 views

### Function behavior based on Head

I'm figuring how to implement a function behavior based on the Head of its argument. I mean ...
124 views

### Functions of two arguments

I am pretty weak on the notion of pure functions, etc. I found a clean solution to my problem so in a sense I've already answered my own question but I don't feel I'm on terra firma. I wanted to take ...
3k views

### “do … while” loop equivalent in Mathematica [closed]

Have I missed something or is there no built-in which mimics the behaviour of do ... while loop? I am looking for a construct that evaluates procedure once and ...
580 views

### Alternatives pattern in a function definition

I thought that I remembered a way to write a function definition using "|", but can't find documentation for it. So for example, I'd want to define: ...
90 views

### Working with functions

I am required to write a function that takes a function as a parameter. ...
105 views

### Convert variable into function

Sorry if this is a duplicate, but I have a variable called H. H is some complicated function of ...
813 views

### Differential operator squared

I defined a one-dimensional momentum operator $\hat{p}=-i\hbar\frac{\partial}{\partial{x}}$ in Mathematica p = -I * h * D[#, x]& and I want to get the ...
163 views

### Patterns of function-arguments in expressions

I want a function that compares an expression with a specific pattern. The expression has always the following form: ...
463 views

### How to combine multiple functions into a single function, indexed bya new argument

I have a system of expressions (matrices) which correspond to increasing orders of precision in a theory. These expressions are quite complex (require about 40+ lines of code to produce) and are not ...
350 views

### Summing Over a Variable Number of Indices

I am trying to figure out the best way to include a variable number of indexes of summation in a program. For example: Suppose I want to define a function $g[n,s]$ that returns the sum \sum_{a_1+.....
240 views

### Extracting function calls from an expression

I have an expression like this: expr = F[0, 1] + 2 F[0, 0] - 17*F[2, 0] and I want to transform it to a list consisting of all function calls with its arguments: ...
97 views

### Using Derivative with list in curly brackets

I'd like to make a formula for a sum containing Derivative where the number of arguments in the latter depends on an input parameter n. Also involved is a list <...
189 views

### How to define an n-variate empirical distribution function probability for any n?

I'm using Mathematica 9.0 to calculate the probability according to the empirical distribution function (EDF) of some sample data. Afterwords this is included in a maximization stage so I define this ...
420 views

### Defining Piecewise Functions in Modules

In short, my question is the same as my previous one except that everything is now wrapped up in a module. The relevant code I'm working with is: ...
83 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 ...
108 views

### Defining a function with global parameters

What I would like to do in Mathematica is something like f[x_] := a x g[a_] := NIntegrate[f[x], {x, 0, 1}] But then of course I get ...
113 views

### Create jacobian Function from a vector Function

This is related to this question and maybe this question. I wanted a function that takes an n-parameter vector function and outputs a Jacobian matrix function, also n-parameter. I think this works: <...
640 views

### Define a function with a function for an input

I want to create the functions $even[f]$ and $odd[f]$ which will apply the formula $even[f(x)] = \frac{f(x)+f(-x)}{2}$ and $odd[f(x)]=\frac{f(x)-f(-x)}{2}$ for an arbitrary $f$. I tried using <...
211 views

### String pattern matching in function definition

I have a function f and its downvalues. I want to code an extra downvalue for arguments of the form "part1:part2" I don't understand why f[a__~~":"~~b__] := {a,b} ...
47 views

### Using Table[ ] vs using Do[Append [ ] ] [duplicate]

Is it generally better/faster to use the Table function over using Do[Append []]? For example, I have this piece of code: <...
If $f,g$ are functions of the independent variables $\{q_1, q_2, ..., q_N, p_1, p_2, ..., p_N\}$, then the Poisson bracket is defined as: \begin{equation*} [f, g] = \sum_{i=1}^N \left(\frac{\partial ...