Questions on writing non-trivial programs in Mathematica. Do not use this tag for questions on plotting/graphics or for questions on doing mathematics with Mathematica, where the focus is more on the math than the program.

learn more… | top users | synonyms

7
votes
1answer
282 views

Find a word's linguistic pronunciation

Is there a way to get a word's linguistic pronunciation given the word as a string? I would like a function LingusticPronunciation such that, for example, ...
8
votes
4answers
273 views

Searching linked lists that contain lists?

Following the advice I've read here and other sites, I've been trying to use the Mathematica equivalent of a linked lists... ...
14
votes
2answers
413 views

Efficient priority queues?

I'm trying to figure out how to transfer the concept of a priority queue to the functional world. Searches have turned up some implementations that use Append and other expense list copying ...
4
votes
4answers
896 views

Numerical differentiation methods

Is it possible to write a code in Mathematica that implements various differentiation methods (like forward, central, extrapolated, etc.)?
17
votes
1answer
183 views

How to get Cases to wrap results in an arbitrary head?

A number of functions provide for results to be wrapped in an arbitrary head. This is very important in cases where the results should not be evaluated. Take ...
10
votes
5answers
490 views

How to find first list element that differs from average of N previous elements by more than a given amount?

Given a list of real numbers, I need to write a function that returns the value of the first element in the list that differs from the mean of the previous $N$ elements by greater than $P$ standard ...
6
votes
2answers
252 views

Clustering of peaks in 2D spectra

I'm having some problems clustering data in a 2D spectra and will really appreciate some help. I've been playing around with the FindClusters function but wasn't able to tune it appropriately. Maybe ...
16
votes
12answers
1k views

Pick elements of largest absolute value

For example, given list = {{1, -3, -5}, {2, 1, 6}, {0, 2, 4}, {-9, 2, 6}} should return: {-5, 6, 4, -9} Updated I found ...
3
votes
0answers
53 views

How can I append Mathematica variables to an output file preserving both names and values? [duplicate]

I have a Mathematica program that calculates a series of large vectors that I need to save for future reference (in addition to some scalar values). I want to save all these to a file, tagged by their ...
1
vote
1answer
197 views

What's wrong with my code for finding primes?

From here I found a fast method to make prime list, the python version works well, but my Mathematica version does not. Obviously ,169 is not a prime number. What's ...
3
votes
3answers
269 views

Need help with exception handling

I have read the docs for Catch, Throw, and friends multiple times, and I confess that I find them utterly incomprehensible... ...
7
votes
3answers
609 views

Programming Mathematica in plaintext, i.e. no formatting, non-notebook

I'm new to Mathematica and I've just begun reading Paul Wellin's Programming in Mathematica. The book, like many other books and online tutorials, revolves around using the notebook, with all its ...
0
votes
0answers
154 views
1
vote
2answers
125 views

How to automatically put the part of a variable name after the first letter in symbolized subscripts?

So here is what I have thought: Use ToString and StringLength in order to get the number of characters in the variable name. If it is bigger than one, change variable name by putting everything but ...
6
votes
2answers
110 views

Consecutive Print to target same output Cell

Is it possible to conveniently direct the output of consecutive Print statements to the same output without actually accumulating the output in a temporary string/variable. This would be useful in ...
0
votes
0answers
83 views

Implementing a back button (in CDF)

I have a rather large notebook, which contains a lot of hyperlinks to different parts of the notebook. Is it possible to make a back button (maybe as a docked cell button?) so that when a reader ...
26
votes
2answers
1k views

when is f@g not the same as f[g]?

I have always thought that f@g will give the same result as f[g] in all cases, and it is just a matter of style which one to use ...
0
votes
1answer
202 views

A problem on generating convex hull

For example, I typed the following: ...
17
votes
1answer
353 views

Underlying Algorithms for List Manipulation Functions

Does anyone know, or know of a link for the underlying algorithms used for list manipulation functions? Specifically: Union with and without the ...
5
votes
1answer
165 views

Are there functions or packages in Mathematica to sort subsets in lex order, colex, revlex, etc.?

I am looking for non-canonical sorts of lists. A function that would give: Sort[X, "order type"] With "order type" being colex, revlex, etc.
41
votes
4answers
1k views

Automatic e-mail/text message when a calculation has finished?

Sometimes Mathematica takes quite a while to finish calculations and it would be convenient to be able to move away from the computer while it is working. I was wondering if there is any "clever" hack ...
2
votes
0answers
107 views

Force Dispatch to generate dispatch tables

Dispatch creates hash tables only for lists of length larger than 3. Is there any way to force MMA to create hash tables even for lists of length smaller than 4? ...
2
votes
1answer
183 views
4
votes
1answer
73 views

Constructing an Array from typed expression

I want to produce an array from expressions given by test[one][1] = 3; . . test[one][5] = 7; etc. Normally would use ...
2
votes
1answer
248 views

Call Functions From File Without Modifying Context (Sandbox)

Let's say I have file named test.m containing test[arg1_] := ( Print[arg1];) What is the best technique for calling test like ...
1
vote
1answer
94 views
0
votes
3answers
116 views

Why is my funtion is wrong? [duplicate]

My aim is to know whether the data has same element. ...
4
votes
3answers
212 views

Better code to solve number puzzle [duplicate]

Question: (34 O 5 O 6 O 8 O 9 O 1) O 2=2008 Replace the Symbol of "O" to "+" or "-" or "*",and make the expression is true. My solution: ...
1
vote
0answers
34 views

How can I convert a list to an expression? [duplicate]

For example, I have the following list: {x1,op1,x2,op2,x3,op3,...} And I would like to convert the list to the following expression: x1 op1 x2 op2 x3 op3 ...
7
votes
1answer
156 views

The Flat Attribute, Unevaluated and the Evaluation Process

To make this question easy to follow let's give some symbols a couple attributes. Attributes[f] = {Flat}; Attributes[s] = {Orderless}; Now consider the ...
24
votes
3answers
914 views

Getting serious about Mathematica programming

I'm at a point in my Mathematica journey where I need to be a little bit more strategic about my coding. Presently, I have a bunch of notebook files organized using the filesystem of the OS and ...
13
votes
0answers
285 views

What Mathematica features and idioms have n^2 complexity or worse

Here are a few: AppendTo[data, elem], Sort[data, test], in some cases use of ___ (as ...
2
votes
2answers
352 views

Matrices and polynomials: MMA 8 vs. 9?

I want a function to take a polynomial from a list, plug a certain matrix T into that polynomial, and return the answer as another matrix. My program uses the applyPoly function suggested by a user in ...
2
votes
1answer
184 views

Differential operator involving permutations

I would like to construct an operator in Mathematica of the following form, $$D_i=\partial_i +\sum_{i \neq j}^n\frac{1}{x_i-x_j}p_{ij}, \quad i=1,...,n$$ where $p_{ij}$ is a (symmetric) permutation ...
1
vote
1answer
196 views

Pseudo-code for rules of probability?

I am having a hard time in Stats understanding some basic rules of probability and set-theory, namely $P(A|B)$, $P(A\ \textrm{and}\ B)$ and $P(A\ \textrm{or}\ B)$ where $A$ and $B$ depend on each ...
5
votes
2answers
193 views

How to group lists that own one common element?

I have produced a list of sub-lists by the following: ...
0
votes
1answer
109 views

Conditioning on group of functions

I have two sets of functions which I want to implement them in a single function with an option indicating which set of functions should be used. Suppose that I have two lists like:(updated example) ...
4
votes
1answer
918 views

Mutual Information involving two matrix states

I basically retrieved the following technique of evaluating the mutual information involving two matrices from this site at http://bmia.bmt.tue.nl/People/BRomeny/Courses/8C080/default.htm The ...
1
vote
2answers
183 views

How to automatically restart Mathematica kernel after out-of-memory error

I want to run a Mathematica code repeatedly, even after the kernel shuts down when it is out of memory, because I have designed my program to continue appending the data to a file. Currently, I have ...
2
votes
1answer
88 views

Map and Scan ignore HoldFirst

I am trying to write a simple function that takes a list of data and outputs it to a file. I'd like the name of the file to be the same as the variable that holds the list. It seems that giving a ...
2
votes
0answers
165 views

Lazy evaluation/loading of parts of an expression

Is it possible to have an expression x such that its elements are only evaluated when they are individually accessed, for example when evaluating statements like ...
15
votes
1answer
271 views

A fast, robust DropWhile

For reasons that have never been entirely clear to me, Mathematica has had a built-in TakeWhile function since version 6.0, but has no equivalent ...
2
votes
1answer
209 views

Optimal image quality using Rasterize Function

Based on previous posts about plotting two y axes on the same x axis, I wrote this function: ...
0
votes
0answers
93 views

Inconsistent results in fits from NArgMin

EDIT: Just realized I had misspelled "inconsistent." I'm using version 7.0. I'm trying to fit a (noisy) data set to a large-order polynomial. (Just for context: there isn't a model for the ...
3
votes
0answers
223 views

Malliavin Derivative with Mathematica is it possible?

Is it possible to define a Malliavin calculus with Mathematica 9? Consider a random variables on the Wiener-space $\Omega=\mathcal{C}([0,1])$ of the form ...
1
vote
1answer
182 views

Making an animated simulation without procedural loops

I'm still new to Mathematica and this is the first time I've wanted to do something more complicated than plotting and changing parameters of mathematical functions. I want to make a simple ...
3
votes
1answer
118 views

Difference between Directory[] and NotebookDirectory[] .. a trailing /?

The following was the code: Directory[] NotebookDirectory[] The output was ...
5
votes
5answers
189 views

On reimplementing the Select function [duplicate]

I am working through the course Programming Paradigms via Mathematica. One of the exercises asks that you construct a function that mimics Select,even with three ...
8
votes
1answer
135 views

Is it possible to write a function immune to symbol redefinitions in any Block surrounding its invocation?

Normally, semantics of symbols used in a function definition can be changed by their redefinitions in Blocks surrounding the function invocation: ...
10
votes
2answers
426 views

Dynamic Programming with delayed evaluation

By using dynamical programming, we can save intermediate steps for recursive relations, as in f[n_]:= f[n] = f[n-1] + f[n-2] However, this only stores ...