The tag has no wiki summary.

learn more… | top users | synonyms

1
vote
1answer
70 views

What is happening in Map[Function[x, x^2], a + b + c] from the Pure Function tutorial

The Pure Function tutorial gives an example: Map[Function[x, x^2], a + b + c]. I would expect the output to be (a + b + c)^2, ...
1
vote
2answers
85 views

`Slot` (#) interfering with evaluation

In the following I am using one function makeFunc to assemble two functions a[t] and b[t] to ...
1
vote
1answer
59 views

How to input pure function to package?

I would like to input a pure function into a custom written package, but am running into a variety of errors. The package I have created is as follows: ...
0
votes
1answer
82 views

Replacement rules in combination with pure functions to make a change of variables

I have defined my function in this way w = f[r,Θ] ; After some calculations i obtained my results with respect to the previous function. For instance: ...
0
votes
1answer
50 views

Can I make a function which depends on several arguments which are not independent?

Here's a simple example Suppose have the permanent relation that z is proportional to xy^2, for real numbers s. z = s x y^2 Now, we are interested in ...
2
votes
1answer
80 views

Recursion when randomizing elements in a list

I want to randomize certain elements of a list; Since the code list = {a, b, c, d, e, f, g}; list[[{1, 3, 5}]] = RandomSample@list[[{1, 3, 5}]]; list works fine, ...
2
votes
1answer
79 views

Need to run evaluation 2 times

Why does this only work after running the evaluation 2 times? ...
0
votes
1answer
54 views

Pure function in Nest

I can't figure out what I'm doing wrong here: Table[Nest[# + 0.1 * -i * #^2 &, 2, 1] , {i, 0, 0.5, 0.1}] (* {2., 1.96, 1.92, 1.88, 1.84, 1.8} *) The problem ...
5
votes
1answer
161 views

How to use Compile to efficiently apply a function to every element of a list

Let's say I have a list of random numbers; list = Table[Random[], {100000}]; I want to apply a function f in every element of ...
1
vote
0answers
86 views

Defining an operator

Let s be a positive integer and let DifferenceDelta be this function with step = 1. Define ...
1
vote
1answer
103 views

Defining a function of a distribution

I have a discrete- time and space markov process that I want to evolve given an initial distribution. To that, I defined ...
0
votes
1answer
211 views

How to combine two usages of # into one and speed up the code?

I have a function num with two variables, matf and matg. How can I combine the last two lines of code below into one? The code is aimed to find out the maxiaml count bel when we give each $i3 = ...
0
votes
2answers
207 views

How combine pure functions of several slots? [duplicate]

How can one define in a functional way a 1st-order linear differential operator involving several independent variables that can then be applied to a function of that many variables? Consider an ...
1
vote
2answers
236 views

How do I create matrices with arbitrary list restrictions?

I want to randomly generate a square matrix of dimension n with entries in the list StartingEntries, and also satisfying that for any such matrix M, the matrix Inverse[IdentityMatrix[n] - M] has ...
3
votes
1answer
101 views

How to make InverseFunction work on function defined with restriction on arguments

This example works to define InverseFunction on the first argument of a function ...
3
votes
5answers
533 views

Find the slope between adjacent points in a list

I have a list of two dimensional points that are ordered by their x-coordinate. I would like to calculate the slope between all adjacent points. I'm familiar with the use of pure functions in Sort ...
20
votes
2answers
524 views

Is there any way to define pure functions with optional arguments?

For example consider the following function: Function[{u,v},u^2+v^4] Is there anyway to define default values for the variables ...
9
votes
1answer
183 views

Pure function with attributes of arbitrary number of arguments: Is it possible?

Mathematica allows to define pure function, like Function[{a, b},Length[Unevaluated@a]{b}][1+2,2+3] (* ==> {0} *) Pure functions in Mathematica can take an ...
-5
votes
1answer
148 views

Split dataset based on the first column [duplicate]

I have a dataset which I want to split based on the first column. The data looks like this ...
3
votes
2answers
112 views

Multiplying expressions within a list of pure functions

Let's say I have a list of pure functions that are nice algebraic expressions: say l = {(#1 - 1)&, (#1^2 + #1)&, (#1^3 - 1)&} What's an easy way to ...
11
votes
3answers
180 views

Using Through to evaluate complex expressions

Suppose we're given the expression f*g+h, where f,g,h are all pure functions. How can we evaluate this expression on some ...
0
votes
3answers
87 views

How can I generate a generalized product to two lists in a special way? [duplicate]

Let's say I have two lists, and I'd like to generate a "cartesian product" from these two. Specifically Inputs: A = {{{1}}, {{2}}, {{1}, {2}}}; B = {8, 9}; ...
9
votes
1answer
118 views

What are the scoping rules for function parameters shadowing System` symbols?

Here are some very contrived code snippets, highly unlikely to appear in real code, but still I am curious why they behave like this: ...
8
votes
3answers
240 views

Have I found a big difference between using the short form and the long form of a pure function?

By referring to the Mathematica documentation, I learned to use ##2 to represent all the arguments but the first one. This is a brief way to represent a pattern ...
-1
votes
1answer
190 views

How to define a pure function with a Module?

I was not able to use a self defined (using Module and For loops) piecewise function to fit data. It seems that the problem is that I have to define a pure function. I would like to learn how to ...
14
votes
2answers
198 views

What are Root objects with multiple polynomials?

In Mathematica 9 a new flavor of Root object with multiple polynomials was introduced. For example, ...
3
votes
2answers
104 views

Generating a list of pure variables

I want to pass a list of pure variables to a function, in which the ordering of the variables matters. For instance, if I want a palindrome, my function might be: ...
5
votes
1answer
277 views

nested use of Apply/Map/MapThread in pure functions

1. My main question I have a function with two argument slots. I wan't to apply this function to 2 lists with different length's. I thought in this solution: ...
1
vote
2answers
68 views

How to construct a new list made from a function that operates on two lists

I need to take two lists (each list contains the number of moles of a chemical). I have a function calledFraction that takes the each entry of the list and then calculates the mole fraction of ...
5
votes
3answers
201 views

Multiply list of pure functions by list of scalars?

I am trying to write a function that returns a list of pure functions. The last step in the function, is to multiply the list of pure functions by a list of scalars (i.e. matrix multiplication). When ...
0
votes
2answers
244 views

Expansion in Basis Functions

I am trying to create an expansion of the form f[x,y]->Sum[Cn[x] y^n,{n,1,order}] To replace the function f by the ...
1
vote
0answers
50 views

Confusing efficiency and evaluation when returning pure functions? [duplicate]

I have a function that takes some time to evaluate, that's meant to be a polynomial approximation to a function. The polynomial is defined by a list of coefficients, so I have the function ...
1
vote
0answers
45 views

Definition of differential operators [duplicate]

I am curious how differential operators are defined in Mathematica. More specifically, if the Laplacian function wasn't available, how would one go on to define such a function in Mathematica directly ...
2
votes
2answers
130 views

Using DeleteCases and Map together

Given: list1 = {{"a",1},{"b",2},{"c",3}} I would like to delete any pair in list1 that does not have a first element that belongs to list2. Example 1: If ...
11
votes
4answers
430 views

Second level depth pure function?

I have the following working construction: Select[ln125, # == Nearest[ln125, 551.748][[1]] &] Here, ln125 is a one ...
14
votes
2answers
339 views

Using several anonymous functions mixed together

This works: list // BarChart[#[[2]], ChartLabels -> DateString @@@ #[[1]], ChartStyle -> "Pastel"] & This doesn't: ...