Tagged Questions
27
votes
9answers
6k views
Generating a Sierpinski carpet
I am trying to draw a Sierpinski_carpet. I have code that works, but I think there is a more elegant way to do than my way. Maybe I couls use Tuples or ...
10
votes
3answers
339 views
What is Mathematica's equivalent to MATLAB's filter function?
The MATLAB code
filter(0.5,[1, -0.5], [1:10])
is equivalent to
Rest@FoldList[(#1 + #2)/2. &, 0, Range[10]]
I don't ...
2
votes
2answers
111 views
How to achieve Set+Part like behaviour in custom Set function?
So I've been toiling away on my DataFrame package. I've been trying to get Set to work with it, but it seems it either can't be done (ie via ...
2
votes
1answer
113 views
Rookie mistake in defining a function with Modules?
I can't figure out what's wrong with this piece of code. I'm trying to define a function that counts the occurrences of x, y and ...
2
votes
3answers
230 views
How do I construct a pure function to extract data fields from records that are strings?
How can I get from data segment format to the final segment format with a pure function? The data fields are fixed length. There are no separators between the fields.
a) list
...
0
votes
2answers
304 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 ...
1
vote
0answers
95 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 ...
6
votes
1answer
121 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 ...
2
votes
2answers
276 views
Creating custom functions with multiple arguments
I am hoping that this isn't a stupid question so feel free to vote it for closure. Google failed somehow.
I want to define a custom function (more complicated than the usual ...
9
votes
4answers
255 views
Can a function be made to accept a variable amount of inputs?
I have a function that takes two inputs and processes them for a single output. What I need is one that can take a varying number of inputs. and process them to a single output. Is this possible in ...
12
votes
1answer
177 views
How to make a function like Set, but with a Block construct for the pattern names
How can we define a function that works like f[x_]=ComputeSomething[x] and treats x as a variable that does not have a value? ...
27
votes
6answers
858 views
Functions vs. patterns
Every time I define a new function, I wonder which construct I should use: true functions obtained by using Function, or rule-based syntax. For example, these are ...
21
votes
3answers
624 views
Sum over n variables
What is the most painless way to sum over n variables, for example, if the range of summation is $i_1 < i_2 < i_3 < \dots < i_n$, where $n$ is an argument of the function in question?
Is ...