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

33
votes
2answers
617 views

How safe is the use of Block and Internal`InheritedBlock

For many questions on this site answers are given which suggest to use Block and, especially for more advanced topics, ...
8
votes
2answers
1k views

Dynamic graph visualisation using JLink/Java and GraphStream

Visualising the addition of new nodes and edges to a graph to 'watch it grow' is to something Mathematica is not suited to by default. However this type of animation really helps convey the emergence ...
1
vote
2answers
124 views

Counting a cardinality of a subset satisfying special property

Suppose that we have a set of 9 2-dimensional vectors $c$ by m=3; n=2; c=Tuples[Range[m],n]; We want to define a subset $S$ of vectors in $c$ by the following: ...
12
votes
3answers
290 views

Notebook vs. DocumentNotebook; display a Notebook inline, like a DocumentNotebook

If you evaluate a DocumentNotebook[] expression in the front-end, it nicely displays inline, inside of an output cell in the current notebook: For my purposes, ...
3
votes
1answer
62 views

Combination of CellPrint and PrintTemporary, or DisplayForm for Cells

I'm programmatically generating some formatted output that generates a cell in the form of a Cell[] expression. For instance, the output might be ...
4
votes
2answers
196 views

How can I write a Do loop that iterates over N iterators when N is not known a-priori?

For any positive integer $n$ which is not specified a priori, I can make $n$-tuple vector $v$ by v = Array[a, 1, n]. Now, given that $n$ is a positive integer which ...
0
votes
1answer
413 views

What is wrong with this Cobweb plot [closed]

Something is wrong with my cobweb plot code but I couldn't figure out where do the mistakes come from. So basically we have the iterative map $x_n == x_{n-1}^{2} - 3 \mu$. I would like to draw a ...
3
votes
1answer
179 views

Using single replacement rule to convert algebraic expression

I have been trying this problems for hours and cannot find any helpful clues. How can I convert $Sinh[3\theta]+Sinh[\theta]$ to a rational function of x given $2Sinh[\theta] = x-x^{-1}$ by using only ...
1
vote
1answer
201 views

Solve this equation symbolically

I am trying to solve the equation for the quantity r = y/x symbolically: 3/y^4 == 3/x^4 + a/(x + 2 y)^4 with the requirement that we need to perform the ...
2
votes
1answer
228 views

Range of stability for iterative map

Using linear stability analysis, I would like to compute the range of stability of the fixed points and the 2-cycles of the following iterative map: $x_n = x_{n-1}^{2} - 3\mu$. Setting $x = x^{2} - ...
1
vote
2answers
276 views

Doing vector manipulations on Mathematica

This is hopefully a simpler version of this previous unanswered question of mine. Let me just focus on the two expressions $F_2^{(s)}$ and $F_3^{(s)}$ given in A.3 and A.4 of page 19 of this paper. ...
4
votes
3answers
149 views

Modify this code using Module and While

I have written a recursive function and would like to re-write the code using Module AND While to compare the timings. Here is my recursive function for f[n], where 6 n f[n] = f[n-1] + n! for n>0 and ...
0
votes
0answers
39 views

Generating partitions of a set with a specified size of the parts [duplicate]

I tried the following (inspired by the answer here) myList = {a, b, c}; Needs["Combinatorica`"]; SetPartitions[myList] and I got this answer, ...
4
votes
3answers
292 views

Unexpected behavior of Unevaluated

Maybe it is about time I read some proper text about the main loop. Maybe I should not care (so much) about Unevaluated (as Leonid suggests). But I think this is an interesting question anyway. This ...
3
votes
0answers
139 views

I am missing a function like HoldPattern

Temporary message: I am planning to edit this question, making the examples less confusing and by moving the things that are confusing to a separate question For any confusion about expressions that ...
2
votes
1answer
147 views

Is it possible to treat starting values as variables?

I have a problem where I am using FindRoot a gazillion times over a grid of parameters. I need to allow the starting values to vary a bit with the parameters to get it to converge. Here is a simple ...
14
votes
3answers
165 views

What does `: Hold[$IterationLimit]` mean?

In this answer, what does the : Hold[$IterationLimit] part of the following construct do? ...
4
votes
2answers
183 views

why set values in this way doesn't work?

question is as follows define a list ttt={1,2}; and if I set values in this way {ttt[[1]],ttt[[2]]}={3,4} then the value ...
0
votes
2answers
69 views

How can i execute several Commands in one text file and use it in notebook?

I want to execute several commands in one text file and use it in notebook by Get[] command. for example: ...
14
votes
3answers
442 views

Comparing Mathematica expressions like diff

I am looking for a way to compare (or "diff") two Mathematica expressions, similarly to how to diff utility can compare two text files and report the differences. Has anyone already written such a ...
1
vote
1answer
418 views

How to run Mathematica using Mac Terminal

My question is so trivial and I'm sure most people in here know exactly how to do this, however I still don't know how to run Mathematica in Mac terminal! I need to use all the cores of my computer ...
11
votes
1answer
317 views

Triggering actions when a variable is set

Some built-in variables trigger actions when their values are changed: ...
1
vote
1answer
121 views

How can I import sound from within a Manipulate expression?

I want to import sound from a file, record, and import sound. ...
0
votes
0answers
20 views

Conflict among Permutations and Graph utilities once Combinatorica is loaded [duplicate]

I have tried to figure out and solve the problem of compatibility of Permutations and Graph utilities of Mathematica once the Combinatorica Package is loaded, but I failed :(. Could anyone explain me ...
0
votes
2answers
208 views

characteristic polynomial based on differential equation

I have this differential equation: $$\ddot{x}-\frac{1}{6} \dot{x} - \frac{1}{6}x = e^t$$ When I DSolve it looks like this: ...
1
vote
3answers
203 views

Minimize user defined function

I have a user defined function h[i_,j_] and I would like to find its minimum value over all integers $1 \leq i \leq 100$ and $1 \leq j \leq 100$ and $j \leq i$. I would just like Mathematica to try ...
14
votes
2answers
1k views

Fastest way to measure Hamming distance of integers

I am looking for a fast and robust way to calculate the Hamming distance of integers. The Hamming distance of two integers is the number of matching bits in their binary representations. I expect that ...
2
votes
2answers
296 views
11
votes
3answers
370 views

Custom functions by delegating options in a specific way and using core functions

I'd like to create a custom function that does essentially the same as a core function of mathematica but uses different default settings. Example: I want a Plot function that uses Mathematica's core ...
7
votes
3answers
278 views

Unencoding encoded URLs in a function

Is there a built-in function for decoding encoded URLs in Mathematica? I would like to convert an encoded URL, for example ...
18
votes
4answers
598 views

Accessing list elements by name

First, a bit of a long introduction to my problem: I only have a few weeks of Mathematica experience. I am creating a mathematica application that calculates some material properties of steel based ...
2
votes
1answer
148 views

Combining two notebooks

I have a notebook which contain all the variables and defined functions. I want to do two tasks. As an example, I want to find the density and energy which have equations in terms of above mentioned ...
4
votes
0answers
81 views

Is there a way to check whether two notebooks share the same variables?

When I code in Mathematica, I often re-use code from old notebooks which fulfilled a specific purpose; for example, one testing for soft matches in strings, or one that identifies outliers on a graph ...
35
votes
9answers
7k 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 ...
5
votes
1answer
445 views

NestList and Euler's method

I am new to mathematica and so just experimenting with various programming constructs. Recently have been looking at NestList and how I could use this to implement ...
18
votes
3answers
2k views

Fastest way to calculate matrix of pairwise distances

It is a very common problem that given a distance function $d(p_1,p_2)$ and a set of points pts, we need to construct a matrix ...
1
vote
1answer
173 views

Automating sequential import of data from web

I am trying to import data from multiple web pages hosted by a single online source. The data is posted by the source as one data set per web page for each week of the year. I would like to import the ...
24
votes
4answers
912 views

What tools can help in realizing tail recursion?

I had nice discussions with Leonid and Rojo that got me interested in tail recursion. Tail recursion is not always easy to realize with Mathematica, so it would be nice to have some tools to help with ...
1
vote
0answers
239 views

Data structure for a list of actions

The idea: I need to generate a sequence of events then run a "propagator" over the list of events where the "propagator" will update the state of the following event. I can then write functions that ...
11
votes
3answers
938 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 ...
12
votes
2answers
417 views

Need help coding/creating a recursive list

I have two lists A and B, each with 99 real numbers. I want to form a list, C, whose ...
1
vote
2answers
471 views
1
vote
2answers
311 views

Select rows from table by keys

I am looking for a way to iteratively select all sublists with the same ID (my 1st column, residual columns are AbsoluteTime entries). First, I obtained the list of ...
5
votes
0answers
175 views

Convert logical relational expression to / from disjunctive and conjunctive forms?

I would like to convert logical relational expressions in disjunctive form, e.g., $$(x \lt -1) \lor (-1 \lt x \lt +1) \lor (x \gt +1)$$ into conjunctive form, e.g., $$(x \ne -1) \land (x \ne +1)$$ ...
21
votes
3answers
347 views

Efficiently appending points to a NearestFunction

I have a program which works with a list of points (in 3D, but it could be in 1D as well, it won't make a difference). Within a loop, it keeps adding new points to the list. To calculate the ...
5
votes
2answers
3k views

Solving a tridiagonal system of linear equations using the Thomas algorithm

I'm trying to write a function that can solve a tridiagonal system of linear equations using the Thomas algorithm. It basically solves the following equation. (Details can be found at the Wiki page ...
2
votes
0answers
77 views

SetDelayed and avoiding function calls through memoization [duplicate]

I am fairly new to Mathematica. I am working my way through a number of books. I have been looking at the use of SetDelayed and want to confirm that my ...
0
votes
1answer
91 views

Collecting roots of different equations and create a list

I solve two equations and have two solutions one by each equation. I want to create list of these roots. Could anyone please help me? Appreciate it. m02R150 = FindRoot[P1 == 0, {E1, 0.07, 0.1}] ...
5
votes
3answers
579 views

Keep function range as a variable

Plot[2*x^2 - x + 2, {x, -1, 1}] plots a function of x from -1 to 1. As far as I can see, I cannot "save" this range in a variable: ...
26
votes
5answers
958 views

Voronoi diagrams for generators other than points

Any suggestions how to determine Voronoi diagram for sites other than points, as e.g. in the picture below? Input is a raster image.