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

-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
87 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
57 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
47 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, ...
9
votes
1answer
155 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
59 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
96 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
80 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
39 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
143 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
38 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
59 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
126 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
192 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
47 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 ...
7
votes
1answer
272 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
111 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
183 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
60 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
78 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
130 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
56 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
114 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
202 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
186 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
64 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 ...
2
votes
2answers
61 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] ...
1
vote
1answer
155 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
52 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 ...
0
votes
0answers
32 views

How to evaluate NMinimize inside a function

I want to define a function that returns a sum of differences of some points to a given function. To obtain these differences I would like to use NMinimize, but if I implement that straightforwardly, ...
5
votes
2answers
237 views

Optimising coefficient finding functions

I'm seeking a generalisation to this question, where I am looking to list the coefficients (without repetition) to monomials of the form ...
0
votes
0answers
30 views

Remove list head to insert as arguement [duplicate]

I'm trying to use a set of terms, e.g., {x,y,z}, as an argument for another function with doesn't take in a list but a series of variables (e.g. need ...
0
votes
1answer
47 views

Semi-delayed assignment: analytic now; numeric later

The problem starts with a medium-complicated function, f[y0_,y1_,y2_,s_,d_], with everything Real. The innards of this function don’t matter here, except to say that it is analytically differentiable. ...
0
votes
0answers
34 views

Doing a repeated calculation on unique chunks of data based on a value in a column

First post ever on a forum, please bear with me if I don't get it right the first time :) I'm making a script for someone that imports a data file, generates some histograms, tables, and outputs them ...
1
vote
1answer
53 views

How to modify the output result of an evaluation

For ease of notation, I have defined a function, $f$, that defines the permutation of Bosonic particles such that it has the following properties (the form of $f$ is irrelavent for this question): ...
7
votes
3answers
238 views

Why these ways of defining a function with variable number of arguments fail?

First: I know about the correct way to define a function with variable number of arguments: Clear[f] f[s__] := Plus[s] f[1, 2, 3, 4] (* 10 *) BUT I ...
4
votes
2answers
136 views

Nested mapping of a function

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

Question about output of a function

I'm pretty new to programming in Mathematica and have a question. I wrote this function to factorise large numbers. The outputs are almost as expected, but I don't understand where the null's come ...
3
votes
5answers
295 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 ...
3
votes
2answers
201 views

Improve timings for calculating coeficients

Is there a quicker way of finding ther coefficients of something like $$(x_{1}^{2}+x_{2}^{2}+x_{3}^{2}+x_{4}^{2}+x_{5}^{2}+x_{6}^{2}+x_{7}^{2}+x_{8}^{2}+x_{9}^{2}+x_{10}^{2})\times\\ ...
10
votes
1answer
174 views

Copy Built-in function to new name

It is know that some built-in functions are system function and changing their properties may cause trouble. Suppose for example I want to change features of Cases: ...
1
vote
1answer
50 views

Mathematica defines a function as list

This might be a very silly question but i'm defining a function as: \[Chi][AR_] := ((AR^(2) - 1)/(AR^(2) + 1)); which is clearly a scalar function of AR; however ...
0
votes
2answers
40 views

Custom function call does not return a value

I have written the following code to implement a PCA algorithm. It works on standalone basis, however when I put it into a function that is called the following ...
3
votes
1answer
254 views

Creating the Nabla operator as a operator

How can I define the nabla-operator as a an operator, acting on everything to the right of the operator! Also taking \[Del]^2 would give the second derivivates. I wish to be able to write ...
0
votes
2answers
94 views

How do I define the following piecewise function?

For 0<=t<=10, if 5t<=n<=5t+2, then f[n]=4n, and if 5t+3<=n<=5t+4, then f[n]=4n+1? I would like then to use the specific values of f[n], for all n between 0 and 54 (t here is any ...
7
votes
2answers
300 views

Using up-values and down-values

I have a problem I'm trying hard to find a solution for, although I don't know if a solution exists. The following rules produce the result e[2].f[] ...
1
vote
2answers
95 views

Theory => practice: constructing a function “functionally”

I've read the Mathematica documentation and am certain there's way to do this with functional programming, but can't quite conceive yet how. I've taken a simple example (stating the series for ...
3
votes
1answer
115 views

Given a list made up of subsets of an alphabet, how can I use associations to create a Boolean dictionary of the given list

I have a list of 30,000 elements, each of the element is a list in itself {{a, b}, {p, q, r}, {a, p}, ..., {z, x}}. Second one contains unique elements ...
2
votes
1answer
101 views

Table of references [duplicate]

I have a list of variables (say a, b, c, d, e) that I want to assign in a single command. {a,b,c,d,e} = {1,2,3,4,5} would ...
1
vote
1answer
47 views

Summimg peculiar nestings

I have some lists with peculiar nestings: ...