Questions tagged [functional-style]
Questions about Mathematica's functional programming style, including the use of pure functions (Function[], #, &) and functions such as Map, Apply, Nest, and Through.
470
questions
1
vote
0
answers
47
views
Evaluating step functions
Please guys, how do I tell Mathematica to return f(a-b)= 1 if a=b and 0 otherwise?
This means that f(0)=1 and f(x)=0 for x>0.
4
votes
2
answers
130
views
How to use functional iteration with changing function?
I recently came across this problem on reddit. The problem is supposed to be read like a snake, and the result of each succesive operation is sent to the next operation:
There are 9 blank boxes and ...
2
votes
2
answers
68
views
How to implement this zip function? zip[g,{f[{a,b}],f[{c,d}]}] to f[{g[{a,c}],g[{b,d}]}]
I have a function that returns an expression in the form f[{a,b}], and I use this function twice and assemble the expression ...
4
votes
2
answers
319
views
Get cumulative sums in a list without using a for loop [closed]
I want a list of the kind list = {a,a+b,a+b+c} for list plotting. The quantities of the list come from a function. Let us say this is
...
4
votes
1
answer
82
views
PatternTest in Function
This is probably trivial and already asked but I did not find it.
How to use PatternTest inside Function (...
2
votes
1
answer
72
views
Expression as parameter to function that evaluates it, best way to do it?
I need a function fSum that computes the angular sum for some expression, like this:
fSum[3 Sin[2 x], 0, 2 π]
Or from a predefined function, like this:
f[x] = 2 Sin[3 x];
fSum[f, 0, 2 π]
Or plots it ...
0
votes
2
answers
62
views
Problem with $ sign in temporary function parameter
I am having a problem with $ sign in the name of a parameter to a temporary function. The functions I have should compute the angular sum (or turning angle) for some expression generated by function <...
3
votes
1
answer
94
views
Quickly processing long lists using SequencePosition
Overview
SequencePosition does exactly what I need; however, it seems to be very slow for long lists. Is there an input option that would allow it to process faster? Or, perhaps an alternative ...
4
votes
3
answers
656
views
Concise version of MATLAB code
Please see this MATLAB code:
k=0:8;
wk=2 * pi * k/17;
ak=double(wk<0.5*pi)
It generates ak with such a simple expression. To ...
5
votes
1
answer
81
views
Undocumented behavior of Fold for arbitrary heads [closed]
Edit: I'm apparently blind. Sorry! And thanks to those who answered anyway.
Apologies in advance if this is sort of a nitpicky question, but I'm generally very paranoid that I don't fully understand ...
4
votes
1
answer
98
views
How to shorten the plotting code using slots and table? [closed]
Background Information
I have the following Mathematica code:
...
0
votes
1
answer
59
views
How to evaluate expressions which involve derivatives and evaluations of functions in a specific case, via a condition?
I have an expression involving the derivative of an arbitrary function r_0
c0 = Derivative[1][Subscript[r, 0]]
Later I must replace r_0 by several specific ...
6
votes
4
answers
428
views
Subdivide a sequence
Yesterday I couldn't solve a problem which seemed to be rather simple. I tried RepleaceRepeated, SequenceReplace and similar ...
0
votes
1
answer
91
views
How can I apply Residue in a functional-style way? [closed]
Let me suppose that I have got some expression, for example
f_{1}(x)+f_{2}(x)
and also a list of a form:
{1,2}
How can I apply ...
6
votes
8
answers
405
views
Removing duplicates between sublists
I want do delete from each sublist those elements which are contained in one or more of the other sublists. The surviving elements must maintain their original order of appearance.
...