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

2answers
395 views

### How to define a differential operator?

I have a linear differential operator, for instance, $L\left (\partial _{t} \right )=\partial _{tt} - 3\partial _{t} + 2$. I use it in 2 different ways: apply the operator to a function: \$L\left ...
2answers
148 views

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

How to embed and call the correct embedded modules inside another Module? Say: ...
1answer
170 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
181 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
126 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
111 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
73 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: ...
3answers
245 views

### Generating pairs of additive and multiplicative factors for integers

Given an integer $n$, I want 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 came up ...
0answers
194 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 ...
0answers
97 views

### Return Functions from parallel execution of module

I wrote a module which numerically solves an ODE using NDSolve. The result from this is e.g. either ...
1answer
67 views

### Defining functions from expressions of variable lengths

I have a list of symbols that I have defined using d = Table[Symbol["d" <> ToString[i]], {i, 1, n}] giving ...
2answers
309 views

### Building matrices by attaching vectors (columns) and matrices

Having the need to attach a column to a matrix or to join matrices to make longer rows is an operation that I use very frequently and I find the Join function ideal ...
0answers
76 views

### Non Commutative Multiply [duplicate]

Possible Duplicate: Non-commutative symbolic linear algebra I want to multiply two matrices, for example, A = {{e, f}, {g, h}} B = {{a, b}, {c, d}} ...
1answer
245 views

### Matrix Multiplication Modulo 2

I would like to perform matrix multiplication modulo 2. Hence, instead of the usual: A.B I did: ...
1answer
127 views

### How to generalize a formula?

This is a piece of my code: ...
0answers
88 views

### Bad function evaluation

I am having some trouble with this function ...
4answers
164 views

### How to create a composite function from a variable number of components?

Background of the problem: A patient takes a drug every $X$ hours with a half-life of $Y$ hours. How much of the drug will be (exactly) in his system after $h$ hours? For $X=24$, and $Y=24$ I made the ...
1answer
112 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 ...
3answers
137 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 ...
1answer
138 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 ...
2answers
86 views

This works: ...
2answers
104 views

### How to mix Unevaluated property of function arguments with expression assignments?

This is a follow-up to my (solved) question How to distribute a generic function of two arguments (without evaluating the arguments) Say, I have a binary function ...
3answers
110 views

### How to distribute a generic function of two arguments (without evaluating the arguments)

I guess there is an easy way to do this, but I can't seem to figure it out. What I would like to do is to distribute a generic (i.e. without specifying what this function really does) binary function. ...
3answers
221 views

### Composition of mappings not working as expected

I have two functions $f,g:\mathbb{R}^2 \to \mathbb{R}^2$ and I define a third one $h:\mathbb{R}^2 \to \mathbb{R}^2$ as the composition $$h(x,y) = g(f(x,y))$$ I'm trying to get this function into ...
2answers
173 views

### Define product derivative

How do I define the $n$th product derivative of a function in Mathematica? The first product derivative $f^\ast$ of a function $f$ is $$f^\ast(x)=\exp\left(\frac{f^\prime(x)}{f(x)}\right)$$ The ...
3answers
165 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
75 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 ...
1answer
633 views

### “Tag times protected” for this doesn't make sense

I have a property calculator which is in a Table to generate well... a table of properties and growth rates depending on the value of ...
2answers
142 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
143 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
262 views

### NestList on a function with more arguments

I'd like to know if it is possible to use NestList on a regular function with more arguments, such as: ...
2answers
896 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 ...
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: ...
1answer
305 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 ...
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: ...
2answers
212 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. ...
2answers
187 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, ...
2answers
202 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: ...
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 ...
2answers
101 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 ...
3answers
157 views

### Variables Inside Functions Not Evaluating

x = 5*y function1[y_] := x function1[5] Am I wrong in thinking that function1[5] should equal 25? Instead this comes out. ...
1answer
166 views

### Calling part of a  variable in a user defined function

I have defined a function ...
4answers
120 views

### Pack Solve results into a vector

I am currently using a really easy function to get the eigenvectors of a corresponding eigenspace: ...
3answers
201 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 ...
6answers
668 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 ...
9answers
922 views

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

I'm trying to solve the fourth Project Euler's problem with this: ...
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 ...
4answers
321 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 ...
2answers
181 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. ...
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 ...
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 26, "mathjax_display_tex": 2, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.8811678290367126, "perplexity_flag": "middle"}