# Tagged Questions

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.

170 views

### Simplifying already defined symbols

Consider the following code: ClearAll[x, y] x = y; y = 2; ?x ?y This will store $x$ being equal to the variable $y$, and $y$ having the value of $2$. Now switch ...
693 views

### How to make GraphicsGrid with content tight inside it?

I am trying to use GraphicsGrid to typeset some labels for my plots. I found the labels look little better when I use GrapicsGrid vs Grid. The labels have equations in them and not just plain labels. ...
78 views

### union several arrays of same flag(date for example) efficiently

Suppose I have several arrays from data files which look like: arrayi = {{datei1, xi11, xi21, ...}, {datei2, xi12, xi22, ...}, ..., {datein, xi1n, xi2n ,...}} ...
378 views

### How to use Mathematica for traditional programming

I am new to the structure of Mathematica. I understand that in the notebooks, one enters the symbolic expressions and evaluates them. But I need to generate some simulated data and do that a few ...
2k views

### Executing a .m file from the Linux command line

I have some code in a file named Demo-3.m, It can be evaluated in Mathematica 9. The final expression in the file is ...
172 views

### How do I use StringReplace to replace repeated characters?

Suppose I have str = "dededekmkmkmvkfjdedemkvmlvdedekfmmdedededemkmkde" And I want to replace the repeated "de"s to one and produce (in a real example, the "de"...
758 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... ...
266 views

### Recursive Euclidean algorithm in Mathematica

Can anyone explain to me how do I use a recursion, if I don't know the limit? For example, I need the remainder $r$ of the Euclidean algorithm for $\gcd(a,b)$ which equals $0$. I figured out that the ...
174 views

### How do I create an array by applying a function to the index of each element?

I am looking for something like matrix(m, n, f), but for Mathematica rather than MuPAD, and for arrays rather than matrices. That is, I'm looking for a(n efficient)...
314 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 ...
264 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 ...
282 views

### Computing closest set of points to each point in large set — running out of memory (arrays unpacking)

I have a large set of points in 3D and I'm trying to identify all the points that lie within a certain distance of each point. Then using this data store the vector between the pairs of points. I ...
100 views

### How to create some macros

I have two question in one. In the following code, I want to manipulate a plot in a centered cell. It is fastiduous to try always to remember the way to act. Could I define some macro as in a standard ...
156 views

### How can I do a Do While loop [duplicate]

Many languages have a Do While loop, how can I do one in Mathematica ?
323 views

### How to download pictures from webpage automatically?

Today, I read a good web page about love which owns many beautiful pictures. It is fussy for me to download every picture hand-by-hand, so I'd like to use Mathematica to do this case automatically. I ...
107 views

### CreateDocument options needed to suppress the default notebook menu

What are the options needed in Mathematica 10 to suppress the menu on top of any notebook created with CreateDocument? For example, the Messages window as well as the windows generated by ...
121 views

### Assign clipboard object in mathematica when print screen is pressed (windows)

Mathematica runs behind, while another window is selected. When I press print screen, I want mathematica too detect this and call a function with the picture as argument. ...
230 views

Code ...
135 views

### How can I plot the normalized distribution of the Riemann zeta zeros?

Given a list of eigenvalues or a list of Riemann zeta zeros, how can I plot this famous plot found here: On the page referred to, You need to click on "Programs", "The Riemann zeta function" and "...
107 views

### Using function to transform a list

I have a list like that: {{Integer,String},....}, integer ranges from 1 to 900 and String "I" to "IV". And I need to find which pair of {x,y} each sublist is related to, so i can get a new list like ...
153 views

### RandomFunction and Histograms

RandomFunction[QueueingProcess[3, 5], {0, 15}] Histogram[data, Automatic, "PDF"] gives a very nice way to see the histogram based on the specified process. ...
157 views

### Programming for matrix manipulation

I want to write a programme which operates on nd x nd matrices. The programme looks the matrix as a n x n block matrix where ...
135 views

### Apply Collatz Funtion to solve and print the answer

Good day to all! The objective of my task is apply the collatz function for a number x1 and print the exact number of iterations until ...
140 views

### How to define a nestable Baseform function, BaseForm output becomes BaseForm input

Mathematica won't change a number's BaseForm recursively: 63969 // BaseForm[#, 16] & // BaseForm[#, 8] & // BaseForm[#, 2] & Well, I inspected former ...
448 views

### Defining an anonymous function using another function but with fewer arguments

In MATLAB you can use an anonymous function with another function to define a new function with fewer arguments as long you define the excluded argument before, e.g. ...
167 views

### Bare symbol invocation fails but not if used with an argument

How to achieve the following behavior on a symbol f? Background: The main goal is to use the symbol to tag an abstract data structure where downvalues are used to store information. Only defined ...
505 views

### How does FindInstance work?

I was asked a question one day: find an integer n such that the first five digits of 5*7^n is 12345. It's very nice that I can quickly write code like this: ...
148 views

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

The following was the code: Directory[] NotebookDirectory[] The output was ...
753 views

The function ...
132 views

### How to make a pattern to change x^(2/y) to (x^2)^(1/y) for any x and y?

This might have been asked before. Please let me know if it is. I was looking at an interesting Mathematica question in students forum and trying to solve it, and a chance to learn more about ...
107 views

### Matrix Diagonalization programming

I have a very simple problem, with me misunderstanding the use of Modules and Functions in general, in mathematica. I have a function of which I want to input a Matrix, and in the function I want ...
148 views

### Error propagation code

I have a code for error propagation :- ...
124 views

### Efficiently generating plots from lists of differing lengths

I guess this is more of an informatic question. A quite complicated function of mine generates me a list of valid points, depending on a parameter, like this: ...
124 views

### Way to generate all multisets

I have a set $\left\{\{1,2\}, \{3,4\}, \{5,6\}, \{7,8\}\right\}$ (for example) and want to generate all sets of $n$ elements with repetition but without counting the same multiset twice. So I want my ...
250 views

### How to replace While construct to NestWhile(functional-style) correctly?

Recently,I find the program of @J.M. about Get a "step by step" evaluation in Mathematica is a very useful example for learning Mathematica programming. In the function ...
92 views

### EndOfFile error

I have a LARGE file (14.6 GB) that I want to separate into several smaller files. Because of its size, using Import/Export is not feasible, I think the most reasonable way of handling this would be ...
243 views

### My code for solving n queens problem Compile Failed

I want to make my code for solving n-queens problem faster, but it seems that MapIndexed can't be compiled. Mathematica return CompiledFunction::cfse: Compiled ...
87 views

### Fastest way to select the longest cell

I'm trying to learn low-level notebook programming and I have a question. Is there faster way to select the longest cell in a notebook than this: ...
656 views

### Nested Sums to multiple sum

I would like to automatically "move nested sums to the left". I mean, just take out of an expression all the summations and go from a nested Sum to a multiple sum. Something like starting with: ...
145 views

### How can you get the area of a region from an image?

Suppose we have a square of side "L" m, How can I calculate the hatched area, if the corners of the square are centers of circles. It can be generalized to any region? edit: This is the result I ...
185 views

### Image background subtraction using parallel computing

I am developing a program for pattern recognition. I want to use the parallel computing to get a real time application. I have two cameras where each one gives n frames/second. I need to process the ...
165 views

### Composing function returning list and function taking multiple arguments

What is the easiest way to compose a function that returns a list of $n$ elements with a function that takes $n$ arguments. If I know this $n$ a priori, I can do something like ...
178 views

### Writing this loop in Mathematica

OK, so I've never had to write a line of Mathematica code (except for using it interactively as a calculator), but for this it looks like I have to. If someone could provide me with the code for the ...
688 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 ...
413 views

### How to determine cluster membership using FindClusters?

I have a 1000 by 3 data matrix in which for each person we have 3 scores. I want to cluster those persons into 8 cluster using Agglomerative method. I did the clusetring by: ...
107 views

### Generating Palindromic_number [duplicate]

I'm trying to construct Palindromic_number, I came up with this code: ...
71 views

### What options for project development exist if the Cloud and Mathematica Online cannot be used

Due to contractual obligations to protect IP and client information, we unfortunately, cannot use Cloud or Mathematica Online for development in the development of our projects. We are further ...
517 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 ...