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.

learn more… | top users | synonyms

2
votes
0answers
16 views

function definition

could you help me? I would like to define a function over a list of variables like f[a_,b_,c_]:=a+b+c However, when this list is big it makes uncomfortable to ...
0
votes
0answers
24 views

How do I call a function that has a default parameter value? [on hold]

I have defined a function that has a default value for one of it's parameters. ...
1
vote
1answer
42 views

Imaginary terms in the derivative of Jacobi theta function (2) on the real line

I am trying to calculate/plot the derivative of the second Jacobi theta function $d\theta_2(0, e^{-\pi t} )/dt$. Calculating or plotting the function itself works fine: ...
2
votes
0answers
42 views

Construct single InterpolatingFunction from a mathematical combination of other IF's

Let's say I have an interpolated function f, like I might get as the solution to an NDSolve: ...
3
votes
6answers
355 views

All integer should be equal

I have a list of 10 integers: ...
3
votes
1answer
73 views

Is Sow/Reap compatible with Composition?

I'm trying to figure out why these two pieces of code return different results. As expected, f[Reap[Sow[x]]] gives ...
0
votes
1answer
34 views

How to have default case in Which? [closed]

Saying we have a function: a[x_] := Which[x === 1, "AAA", x === 2, "BBB", _, $Failed] How can I make this function to be equal to ...
0
votes
1answer
82 views

How can I generalize this interpolation function? [closed]

I have a data set where I want to evaluate a manual interpolation function. The part shown below expands up to the 7th power currently. I was wondering if it was possible to generalize this part of ...
2
votes
1answer
51 views

Is there a shorthand for Optional with Condition?

I have a recursive function that does some work to an object for a repeatedamount of times. ...
2
votes
3answers
72 views

How do I map a function onto the result of an expression that already has a pure function as an argument

I admit that I have only a basic understanding of the way Mathematica handles pure functions - enough to be dangerous, unfortunately. I have some data that is in a list of lists of lists. I would ...
0
votes
0answers
36 views

Using list of values as argument in a function [duplicate]

could you please help me with a task. I would like to define a function with a list of values as an argument. There is a working code with a values {1,1,1}: ...
1
vote
2answers
58 views

How to make function accept list of rules as an argument?

Considering the list of rules: r= {"a" -> "1", "b" -> "2", "c" -> 3, d -> 231, "e" -> 1.25}; I want to have a function ...
1
vote
2answers
122 views

Minimizing the largest difference between two functions

I have two functions defined on the same domain, $f(x)$ and $g(x)$ where $x$ is in $(0,1)$: f[x_] := (-1 + x) Log[1 - x] - x Log[x] g[x_] := Log[1 + 2 (-1 + x) x] ...
2
votes
1answer
65 views

What is the meaning of two square brackets in function definition? [duplicate]

I came along the following function definition f[a_, b_, c_][r_] = ... with some function on the right hand side. Is this equivalent to ...
0
votes
0answers
22 views

How to create a big jacobian matrix function over some variables of a vector function?

Suppose I have a vector function of $n$ components and it has $n+m$ arguments, $$\vec{f}(x_1,x_2,\dots,x_n, y_1, y_2, \dots, y_{m})$$ where $n, m $ are around 10. I want to create a Jacobian matrix ...
2
votes
1answer
28 views

General function for the expansion of a polynomial of operators

This question is motivated by a Quantum mechanical problem - but in explaining the problem - I assume no knowledge of quantum mechanics. I want to define a function that can expand and simplify the ...
0
votes
0answers
22 views

Function with variable arguments [duplicate]

I wrote a function with three arguments like this f[a_,b_,c_]:=... When I call this function MMA requires the input of all three arguments (e.g. f[1,2,3]). Is ...
-1
votes
1answer
46 views

Create a list of all functions given a set of arguments

I'm trying to examine some patterns on the permutation of elements in finite element functions. I'd like to create a list of all functions (256 of them) on ...
2
votes
2answers
77 views

Dynamic updating of Slot number [duplicate]

I want to change the slot number inside Manipulate[]. Here is a minimal example which does not work: ...
-1
votes
1answer
75 views

I have several functions and how I know which one is the maximum in a certain range?

What I did are the followings These lines will generate a piecewise function pw which tells me the corresponding variable given an interval as follows: Now, I want to get: names of variable ...
0
votes
1answer
82 views

Simplifying code

I have a program where I solve the Lorentz-63 system (system of ODEs). I wish to generalize my program to make my code cleaner. Is there any way to create a function that works in a fashion such as ...
0
votes
0answers
38 views

Piecewise function output response interpretation

Piecewise[{{t^2, t <= 0}, {t, t >= 0}}] Outputs: t^2 t <= 0 t t >= 0 0 True What does the last line of output 0 True mean? Sometimes it ...
1
vote
1answer
41 views

Defining functions that depend upon other functions which depend upon other functions and so on

The problem is that I have to evaluate functions, that take output from previous functions, and combine them to form new functions, and do some operations and evaluate the value at new function. But, ...
4
votes
1answer
113 views

Map at a subsequence of a list

I'm trying to construct a function somewhat similar to MapAt. A basic usage example should look like this: ...
0
votes
1answer
51 views

How to define the following bracket?

My quetion is about the definition of the so-called Courant Bracket. Given two generalised vector field, defined as a formal sum of a vector and a one-form, i.e. $X = x + \lambda,\ Y = y + \omega$, ...
7
votes
1answer
88 views

Context-dependent functions

TL;DR warning! My question is not about getting the length of the ticks correct (although if someone has good suggestions, that would be welcomed). My question is about constructing functions that ...
1
vote
2answers
77 views

Avoid nesting of functions [closed]

is there a way to avoid the "nesting" of functions like f[f[f[a, b], c], d] where a, b, c, d are lists and f is a function that merges two lists with certain ...
0
votes
0answers
35 views

How can I get the covariance result cumulatively?

I am trying to derive the covariance results for n x 4 matrix where n is an arbitrary number. I am trying to derive the covariance for each row cumulatively. For example, I am trying to derive the ...
2
votes
2answers
133 views

Using list elements as function calls ?

Is it possible to take elements of a matrix or list and use them as arguments of a function? I have a matrix of values, something like this; ...
0
votes
0answers
35 views

NestList on a function where one of the arguments is chosen by the user

I need to NestList a function where the user chooses one of arguments. Here it is an example: ...
0
votes
1answer
53 views

Creating a symbolic function dynamically given an array of data

I have a function that is based on the numeric values of a random sample that I would like to maximize: ...
4
votes
1answer
100 views

How can I implement this recurrence equation in Mathematica?

I asked a similar question yesterday but today I realized that I was implementing the wrong function. I have tried changing the implementation but I can't get it to work. Problem: There is a river ...
2
votes
2answers
166 views

How can I express this recurrence function in Mathematica?

\begin{equation} r_{i+1}=r_{i}+V_{i}{\Delta}t \end{equation} Where \begin{equation} V_{i}=(0.01, 0.40) \end{equation} and ${\Delta}t$ is the difference in time. My implementation (this is for ...
0
votes
1answer
42 views

How to make functions recall previously calculated results? [duplicate]

I need to calculate a complicated set of functions dpdv[j_], which depend on a set of variables m[n_]. They are time-consuming to calculate, and I don't know in advance which values I'll need. So ...
4
votes
1answer
144 views

Two identical functions give different answers

I am new to mathematica and I hope this is a simple problem. I have two identical functions that only differ by the variable names: ...
4
votes
5answers
99 views

How can I convert a Piecewise into a nested If?

For later conversion into a programming language where if is the only conditional construct, I would like to convert a Piecewise ...
2
votes
2answers
160 views

Plotting difference between a function and its inverse function

I would like to plot the difference a function and its inverse function. (1/27)*(x^4-6x^3+12x^2+19x) (* where 0<x<5 *) I tried the following: ...
1
vote
1answer
38 views

Function taking arbitrary number of arguments

I have a very similar function to that which a solution was provided by kguler, but am unsure as to how to adapt the solution that was given there. That post can be seen here. The adaptation is only ...
1
vote
0answers
65 views

Find algorithm or generator formula with automated procedure and pattern recognition

I am trying to find a generator formula for the discriminant of a polynomial and believe it would be an interesting problem for the Mathematica community to know how to automate evaluation of certain ...
3
votes
1answer
106 views

How can I overload a function with multiple bracket-slots so f[a][b] and f[a] can coexist?

Maybe this is not even possible: I want to create a function f that can have two input brackets like: f[a_][b_:1]:= a*b and ...
1
vote
1answer
48 views

NestList and RandomChoice from a list of functions

I am tryingg to modify Chaos Game Fractals from Wolfram Demonstrations. The part I am having problem with is this. Original code: ...
1
vote
3answers
102 views

IntegerQ returning False despite setting Assumptions

Why does the following not return True? Assuming[z ∈ Integers, IntegerQ[z]] False I tried this on a fresh session of ...
6
votes
1answer
193 views

How can a function know in which function it was evaluated?

Hello my second question here might be very hard. I am asking for something "magical", if i define a function g and i call it inside a function f, how can g have information about the outer function ...
1
vote
3answers
165 views

Defining functions when there are a lot of parameters

Suppose I have two lists of parameters: $\delta=\{\delta1, \delta2, …\}$ and $\gamma = \{\gamma1, \gamma2, …\}$. The question is: how can one use $\delta$ and $\gamma$ (the parameter vectors) within ...
0
votes
2answers
58 views

Supply a function as an argument to another, and find its minimum

I would like to minimize a function, which is supplied as an argument to another function, and report back the estimates of the values of the variables that result in its minimum. In specific, I would ...
1
vote
2answers
51 views

function definition with a given list of parameters: how to use Evaluate[] properly?

given a list of variables variables = {a, b, c}; I want to automatically define a function f[{a_,b_,c_},x_] := g[a,b,c,x] ...
6
votes
1answer
178 views

Prevent Export from overwriting files

Export["filepath1",Expression1] works for me, but if filepath1 already exists, it will be overwritten. I'd like ...
1
vote
1answer
135 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 ...
0
votes
1answer
45 views

Defining functions of varying, iterative numbers 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 ...