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.
0
votes
0answers
23 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:
...
4
votes
3answers
97 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 ...
4
votes
2answers
98 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 ...
7
votes
1answer
54 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, ...
2
votes
1answer
20 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
...
0
votes
1answer
100 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 ...
2
votes
1answer
123 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} - ...
0
votes
2answers
152 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. ...
3
votes
1answer
113 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 ...
0
votes
1answer
131 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 ...
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 ...
11
votes
4answers
413 views
Can you recommend an efficient method for finding the least integer satisfying my inequality?
I tried find the minimum make
$\frac{1}{2}+\frac{1}{2+\sqrt{2}}+\frac{1}{3
+\sqrt{3}}+...+\frac{1}{n+\sqrt{n}}>15$
Following code is so slow when I use condition
...
4
votes
3answers
92 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 ...
192
votes
10answers
21k views
Where can I find examples of good Mathematica programming practice?
I consider myself a pretty good Mathematica programmer, but I'm always looking out for ways to either improve my way of doing things in Mathematica, or to see if there's something nifty that I haven't ...
0
votes
0answers
33 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,
...
2
votes
0answers
96 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 ...
0
votes
0answers
45 views
Generating partitions of a set [duplicate]
Is it possible to get Mathematica to generate all possible partitions of a set of objects?
(..or equivalently if it can be made to do the cumulant expansion or at least the Gaussian special case of ...
5
votes
1answer
319 views
Multi-objective genetic algorithm in Mathematica?
Is there any implementation of a multi-objective genetic algorithm for Mathematica?
8
votes
3answers
105 views
What does `: Hold[$IterationLimit]` mean?
In this answer, what does the : Hold[$IterationLimit] part of the following construct do?
...
2
votes
1answer
85 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 ...
1
vote
2answers
397 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 ...
4
votes
2answers
140 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 ...
11
votes
2answers
195 views
Listing subgraphs of G isomorphic to SubG
If I have an undirected graph G, how could I write a function in Mathematica to obtain a list of subgraphs of G that are isomorphic to some other undirected graph SubG?
I'd like to learn how to ...
0
votes
2answers
54 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:
...
9
votes
3answers
203 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
votes
1answer
118 views
How can I decrease number of lines of code in a notebook? [closed]
I have too many lines of code and I want to reduce the line count.
For example, I have a notebook with 2000 lines of code, and i want to hide some of it so there are less than, say, 200 lines. Can ...
16
votes
3answers
609 views
Reading periodic elements from a large file
I have a large binary data file (big endian) with 100+ million "rows" of 11 elements, combination of floats and integers.
This is the format:
...
2
votes
1answer
84 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 ...
-1
votes
2answers
142 views
How can I find a function that fits some points? [closed]
I have some points and want to find a function from them. For example, $(-2,4),(0,0),(1,1),(5,25)$. I don't have a function that generates the points.
18
votes
6answers
811 views
11
votes
2answers
123 views
Triggering actions when a variable is set
Some built-in variables trigger actions when their values are changed:
...
2
votes
5answers
295 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 ...
0
votes
0answers
45 views
How can I import sound from within a Manipulate expression?
I want to import sound from a file, record, and import sound.
...
13
votes
2answers
304 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 ...
8
votes
2answers
424 views
How to calculate mix of 4 colors defined in CIELAB L*a*b* model?
I have 4 colors that I converted from RGB to CIELAB L*a*b* model.
How can I calculate mix of these 4 colors when I have (L,a,b) for each such color?
How can I ...
6
votes
1answer
455 views
Handling failed FindRoot calls
I want to handle FindRoot calls which did not converge (e.g "thrown" error message FindRoot::cvmit)
...
19
votes
3answers
996 views
Mathematica as a normal programming language
I'm interested in Mathematica's core language for both practical development and as an object of computer science study. Actually, the former is more of a means to the latter. I would like to create ...
0
votes
0answers
15 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
56 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
95 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 ...
11
votes
8answers
379 views
Any built-in function to generate successive sublists from a list?
Given
lst = {a, b, c, d}
I'd like to generate
{{a}, {a, b}, {a, b, c}, {a, b, c, d}}
but using built-in functions only, ...
2
votes
2answers
425 views
Product of Fibonacci numbers using For/Do/While loops
I want to find the product of the first 20 Fibonacci numbers (the fibonorial). I want implementations using While, Do, and ...
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 ...
9
votes
3answers
147 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 ...
2
votes
2answers
89 views
5
votes
3answers
110 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
...
12
votes
3answers
222 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 ...
23
votes
4answers
837 views
How do I evaluate only one step of an expression?
I am looking for a simple, robust way to evaluate an expression only one step, and return the result in a held form.
The definition of a single step is ambiguous, and this itself is probably worthy ...
7
votes
3answers
293 views
NDSolve and {C, K, Slot} and other built-ins as a variable name
The following problem is an exploration of what causes the error "Input is not an ordinary differential equation" in Mathematica as it seems to have changed from version 8 to version 9.
Specifically ...
6
votes
2answers
205 views
CorrelationFunction for vectors
Mathematica 9 has a new CorrelationFunction. Sadly the joy does not last long, as I can't get it to work with vectors. I would like to make a velocity correlation ...



