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

1answer
384 views

2answers
450 views

### How to correctly call a Module within another Module?

How to embed and call the correct embedded modules inside another Module? Say: ...
3answers
1k views

### How do I designate arguments in a nested map?

Say I have two lists, list1 = {a, b, c} list2 = {x, y, z} and I want to map a function f over them to produce ...
1answer
660 views

### Multivariate Function Approximation With a Large Dataset

I have a nice amount of data from a trading strategy I am working on, where I have two different liquidity parameters as x, y variables. Before entering a trade I am taking the moving average of <...
2answers
455 views

### Pattern that matches colors

Suppose I'm writing a function that takes a color as a parameter; for example: drawShape[color_] := Graphics[{Style[Disk[], color]}]; But if the caller inputs an ...
2answers
185 views

### How is OptionsPattern[] defined? Can I replicate this?

I am writing several functions which all take similar input parameters (a complicated nested list structure). Is there some way for me to define a pattern that can be used in multiple places and ...
1answer
203 views

### Find the derivatives of arbitrary order of a function found using NDSolve

For the following initial value problem BC[b_]:=x[0]==b; eq[b_]:=NDSolve[{equation==0, BC[b]}, x, {t,0,1000}]; body[t_,b_]:= x[t]/.eq[b]; one could define the ...
1answer
96 views

### Why function is evaluated backward?

I have a simple function: f[x0_,y0_]:= Module[{x=x0,y=y0},For[i=0,i<2,i++;Print[x],Print[x+y]];] So when I call it: f[2,3]...
3answers
601 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 ...
0answers
487 views

3answers
591 views

### How to pull scalars out of a function that should act on lists?

Suppose I have A = a vecA B = b vecB where a and b are supposed to be arbitrary scalars ...
1answer
174 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 ...
2answers
241 views

### Function to select a row whose kth element is closest to a given number

I'm trying to write a function that picks out the row of a Matrix whose kth element is closest to some given number that will be given to me. So for example, <...
1answer
368 views

### Modules that initialize themselves on first call

I use a lot of functions that extract a specific data item from a file with many data items. I want these functions to load data (slow) and return the item (fast) on first call, but just return the ...
2answers
1k views

### NestList on a function of several arguments

I'd like to know if it is possible to use NestList on a regular function of several arguments, such as: ...
2answers
5k 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 ...