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

159 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 ...
264 views

### How to define function that can change patterns

Given time series data as follows: data = {{{2011, 1, 13}, 10}, {{2011, 2, 14}, 17}, {{2011, 3, 15}, 20}, {{2012, 1, 16}, 30}, {{2012, 2, 17}, 40}}; ...
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 ...
602 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 ...
2k views

### How to find palindromic numbers (Project Euler #4)?

I'm trying to solve the fourth Project Euler's problem with this: ...
556 views

### Define a function with variables linked implicitly

I would like to define a function $f(x,y)$, with the variables x and y linked by an equation implicitly, so $f(x,y)=f(x(y),y)=f(y)$. Eventually I would like to draw a graph with $f(x(y),y)$ being the ...
106 views

### Testing for a vector of reals [closed]

Suppose I define: RealVector[expr_]:=VectorQ[expr,NumberQ[#]&&Head[#]===Real)]; Then: ...
221 views

...
179 views

### General function taking general number of arguments

The following is an edit of this post, for which a working solution was provided by John McGee. I have a different function and am not sure how to adapt the solution for it: I want to construct a ...
487 views

273 views

220 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 ...
179 views

### func::usage needs to be run twice? [duplicate]

There is an annoying problem that I can't figure out why it's happening. I have defined a usage for a my function tensorA: ...
885 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 ...
102 views

### How does a construct like i : func[arg_] := i = an expression using arg work? [duplicate]

Occasionally I run into a Pattern that looks like i:func[arg_]:=i= an expression using arg I have two questions on this: Can ...
256 views

### How to define a nested function like this?

For example, I want to calculate the limit of $\frac{1}{1+\frac{2}{1+\frac{3}{1+\ldots}}}$. So I want to define: $f(1)=1$ $f(2)=\frac{1}{1+2}$ $f(3)=\frac{1}{1+\frac{2}{1+3}}$ Then I calculate ...
325 views

### How to write complex function definitions at run time?

(Posting as a self-answered question to share a technique I discovered) In a certain project, I have many function definitions in which all parameters should be optional and come with default values. ...
169 views

### Nested mapping of a function

If I use the construct f[#] & /@ f[#] & /@ f[#] & /@ {a, b, c} my function works, but if I use ...
210 views

### How to re-parse (or re-map) character '.' to user-defined function

The default behavior of the character . between two non-numeric characters is to be interpreted as the infix of the Mathematica function ...
512 views

### Force Mathematica not to reduce a fraction

I am interested in a function which would stop Mathematica reducing fraction. If my input is 50/100, Mathematica outputs 1/2, I ...
422 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 ...
268 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 ...
277 views

### can a ColorFunction have side effects?

Can anyone explain this (to me) odd behavior. If I run this code once (fresh kernel) it works as intended. ...