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.
7
votes
3answers
329 views
Rewriting For loop to FoldList or similar
In CrossValidated, the answer to a question on prediction of number of viewers of Gangnam Style is given in R. I have mapped the answer directly to Mathematica:
...
7
votes
3answers
203 views
Restricted accumulation of values
Please consider the following list data. I was trying to accumulate data until the result turns positive the first time and ...
7
votes
4answers
358 views
How to implement dual numbers in Mathematica?
I wonder how can I implement dual numbers in Mathematica, so that all functions work well with them (as with complex numbers).
Particularly, for each function $f$, ...
12
votes
5answers
563 views
How to improve this code for solving the “Mr.S and Mr.P” puzzle?
Mr.S and Mr. P puzzle — "Formalization of two Puzzles Involving Knowledge", McCarthy, John (1987)
We pick two numbers $a$ and $b$, such that $a\geq b$ and both numbers are within
the range ...
4
votes
1answer
151 views
Maximizing functions with Which statements
I'd like to be able to find the maximum value that my Capex function (see below) generates. This is a fairly simple function so I could just add it up but I have more complex functions of a similar ...
2
votes
5answers
294 views
How to leave function unevaluated programmatically?
Is it possible to write a function in such manner, that it can be either evaluated or left unevaluated?
This is a general question. Sample below is just a sample. No need to find solution for this ...
2
votes
1answer
596 views
Using triangulation
I have been presented with 3 known points and the power densities at those points. I need to use those points to find the location of the actual antenna which is generating the signals.
Power ...
6
votes
1answer
166 views
Return a Part by Reference? (For accessing hierarchical / structured data)
Is there a way to return a part of a list by reference, for reading and writing?
I want to do this so I can easily manipulate "rule-styled structured", i.e., hierarchical data that is loaded from a ...
4
votes
3answers
278 views
6
votes
1answer
221 views
Guides for programming CDFs
Are there any tutorials for programming high-quality CDFs, like the interactive calculus textbook presented at wolfram.com?
Mathematica's Help is extremely impressive but it really does not help much ...
1
vote
2answers
211 views
Inputting two arrays for a module in Mathematica
I am relatively new to the Mathematica enviroment and not sure where I am going wrong. I have evaluated the question and understand it, but dont know how to exactly create a module for it.
The ...
1
vote
1answer
280 views
Equivalent of Python's “all” function in Mathematica
The Python function
def isPrime(n):
return all(n % i for i in xrange(2, n))
checks if a number is a prime number by using ...
17
votes
2answers
223 views
3
votes
2answers
102 views
Localizing Pattern Names
When I want to define a function that uses a pattern, how should I localize the pattern name (i.e., x_ localizing the symbol x)? ...
4
votes
2answers
190 views
How can I use Max[] in a function that is passed a list not find the max of the list
For most functions in Mathematica, passing them a list will call the function on each element of the list. For example:
...
2
votes
1answer
177 views
Do “objects” in Mathematica have to be declared?
A while ago I learned a trick which allows one to imitate object-oriented programming in MMA using SubValues:
...
5
votes
2answers
280 views
How can I get exactly 5 logarithmic divisions of an interval?
I'd like to get exactly 5 divisions from x to y on a log scale. Can FindDivisions do this?
0
votes
1answer
317 views
Getting imaginary data from known real data using Kramers-Kronig relations [duplicate]
Possible Duplicate:
Kramers-Kronig in Mathematica
I am trying to get epsilon2 (imaginary part) from known epsilon1 ...
4
votes
1answer
227 views
How to combine a set of Plots, including self-drawn Inset/Lines/Circles?
I have a set of 9 plots which should be combined into one plot. Each of these plots contains a ListContourPlot, some circles, lines and an ...
1
vote
0answers
115 views
Fighting Less::nord at the root: Any unintended consequences?
After being plagued too much by Less::nord and companions, I've decided to try to fight it at the root: The comparison operators. I noticed that typically, the bad ...
7
votes
1answer
269 views
Communication between parallel kernels
Greetings. This is my first post here, also, I am not a seasoned programmer, so any advice pertaining to coding that is not directly related to the problem (stated below) is welcome. I am having ...
8
votes
1answer
446 views
Poisson solver using Mathematica
I am looking for some help with a Poisson solver I am writing in Mathematica. The code is quite long with Arrays plugged in, so the full details can be found at http://pastebin.com/uSrSDcW6
I am ...
10
votes
1answer
152 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 ...
5
votes
2answers
119 views
How to silence all messages associated with a built-in symbol?
The post title's pretty much says it all...
The reminder of this post just describes the little headway I made with this problem, FWIW.
One would hope that
...
4
votes
2answers
154 views
Split string into sub-strings of length n [duplicate]
Possible Duplicate:
Partition string into chunks
How can I split a string into sub strings of length n? For example I have a string
"ABCDEabcde1234"
...
6
votes
2answers
307 views
Web scraping and multi-threading in Mathematica
I'm working in some web scraping using Mathematica, and today, to speed-up the process, I used bash commands (xargs with parallel options with curl and wget) using ...
0
votes
2answers
106 views
How to avoid restart during development? [duplicate]
Possible Duplicate:
How do I clear all user defined symbols?
During package development things get messed up quite often. (especially when playing with notations)
Is there a simple way to ...
7
votes
3answers
192 views
how to read in a file in the same directory?
Now I am writing a small package. I have written several files and put them in the same directory. And some files need to read in or include another file in the same directory. But when I simply write ...
14
votes
3answers
457 views
Are there suitable versioning systems for Mathematica notebooks?
I am considering a project using Mathematica and openCL. I know that the openCL C source code can be tracked.
Has anyone used a versioning site or software so multiple developers can modify a common ...
4
votes
1answer
120 views
Transform sequential cell operations to programmatic workflow
Let's say I have a workflow that involves importing images and turning them into an animated gif.
Here's how I currently have it setup:
Import Images:
...
3
votes
1answer
283 views
Control over depth-first scan and breadth-first scan
Is there a way to conditionally take control/modify the flow during a depth-first scan or the breadth-first scan ?
Say, for example, if a particular node if found, consider it as a leaf-node and ...
5
votes
1answer
318 views
Multi-objective genetic algorithm in Mathematica?
Is there any implementation of a multi-objective genetic algorithm for Mathematica?
4
votes
1answer
195 views
How to organize and run functions?
I am very new to Mathematica. I thought I would try it out for my first assignment in my computer science class. Until now I have only used C-base languages including C#, Java, Objective-C, and ...
2
votes
1answer
176 views
FindMinimum, NMinimize, etc. with external process
I was hoping to be able to use MMA's minimization power to work with an external process. I want to minimize the function 'TryThisNumber[x_]' which sends the value of x to something external and gets ...
1
vote
2answers
198 views
How to insert an expression in a Mathematica program?
I need to insert a very large expression in a Mathematica program. So I first
Put[large expression,"file"]
and then use
Block[{}, Get["file"];...]
to ...
19
votes
3answers
321 views
How can I regroup elements in a list into a tree based on their values?
I have a list of elements in an outline, here is an example that is only 3 levels deep:
...
4
votes
3answers
162 views
Is it possible to replicate the “magic” of OptionPatterns[] with DynamicModule's local variables?
Creating richer interactive interfaces that are generated by a DynamicModule invariably requires more complex data structures and in particular, a larger argument ...
9
votes
2answers
144 views
How can I build an inline documentation utility?
I often have a large function to which I add inline comments, but then I can't see the forest for the trees. How can I make a tool that extracts the comments and tokens within them to generate an ...
18
votes
11answers
639 views
Generating an ordered list of pairs of elements from ordered lists
I have a pair of ordered lists. I want to generate a new ordered list (using the same ordering) of length n by applying a binary operator to pairs of elements, one from each list, along with the index ...
6
votes
2answers
124 views
Is Package development (via InitializationCells) compatible with creating new Notations (via MakeExpressions)?
Can new (lower-level) notations be readily used within package code?
There are a few notational additions that might improve my code base but I'm not sure if these will end up being more trouble than ...
5
votes
3answers
144 views
Scope within Context
To define some package-wide functions/variables, what approach is recommended? I tried to use contexts with the Begin function, but this failed:
...
10
votes
1answer
130 views
Evaluation indicator for a notebook
I have a GUI with a number of TabView and other Manipulate controls. Sometimes clicking from one Tabview to the other can take a while, and I would like to have a global "Please wait" indicator.
So ...
13
votes
2answers
220 views
How to make use of NumericQ[x] = True (and use it safely)?
Basic Issue:
I'm trying to understand the proper use of NumericQ's "magical" capabilities. Please consider the examples below. Actual question and some links are ...
4
votes
1answer
129 views
Help with Permutations
I am currently trying to generate a list of permutations of length 2 of elements of a list of strings. For example:
...
7
votes
2answers
270 views
find subsequences of constant increase
A list like
l = {0, 1, 2, 3, 4, 5, 7, 9, 12, 13, 18, 19}
may have subsequences of constant increase, $a_{n+1} = a_n + k$.
For example:
...
5
votes
3answers
275 views
How to ensure that Polygon[list] plots a simple polygon?
Consider the following code which plots a triangle.
p = {{0, 0}, {.2, 0}, {0, .2}};
{Cyan, Polygon[Dynamic[p]]} // Graphics
Then adding (for example) ...
34
votes
8answers
3k views
How to check if a 2D point is in a polygon?
Background: I use code from An Efficient Test For A Point To Be In A Convex Polygon Wolfram Demonstration to check if a point ( mouse pointer ) is in a ( convex ) polygon. Clearly this code fails for ...
11
votes
5answers
418 views
How to perform a depth-first preorder traversal of an expression?
Due to confusion of terminology on my part I asked the wrong question before.
Since it has already received other answers I shall not edit it, but instead ask the question I meant to in the first ...
14
votes
6answers
491 views
How to perform a breadth-first traversal of an expression?
Mathematica provides functions that perform a depth-first traversal on an expression, including: Map, MapAll, and ...
2
votes
2answers
155 views
Dynamic lists as function arguments
Suppose I have a function that requires a list is as input. I.e.
f[list_]:=DoSomethingWithList
Now, if I pass a variable as Dynamic like this
...



