# Questions tagged [programming]

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.

1,364 questions
Filter by
Sorted by
Tagged with
224 views

### Multi-coloured tree plot

I am trying to create a multi-coloured tree plot (Mathematica 9) where each branch is coloured according to its parent node value. For example, for a tree plot with three nodes, n1, n2 and n3, coming ...
1k views

### Permanently extending the behaviour of functions (like decorators)

Suppose I have a function, e.g. f[x_] := x^2 It works like this: f[5] (* 25 *) I would like to permanently modify it so ...
181 views

### Implement edge contraction function which respects vertex weights

It seems that built-in EdgeContract function doesn't work properly with weighted graphs, to be more precise, I mean that if I'm going to contract edge $e$ which ...
457 views

447 views

### multiple reflections of a laser beam in a triangle

I want to make a animation that multiple reflections of a laser beam in a triangle looked like, I have tried following, but it's not a good way, I'm looking for a better way(Nested solution). ...
52 views

### The comparison between the columns of a Matrix by an algebraic relationship

I am trying to work a program using Mathematica to Compare the columns of the matrix bb by applying an algebraic formula . I will give a simple example explaining ...
86 views

### special boolean operator

I am familiar with some boolean operators. I want to access an operator that does a procedure same as below one. But for simplicity, we can say in the first step we ignore ...
997 views

### In nested For-loops, I want the second For-loop to be evaluated only once in each cyle

I want to print A[0, 0, 1], A[0, 0, 2], A[1, 1, 1], A[1, 1, 2], A[2, 2, 1], A[2, 2, 2] using the following code. ...
105 views

### How can one *force* a front end session to *terminate itself* programmatically?

NB: None of the responses to Programmatically quitting the FrontEnd or running without one? answers the question asked here. If one runs ...
175 views

### Linear programming, Help!

Can someone please help me. I have a function f[x_] := 3*(x - Pi/2)*(Sin[4*x])^2 + 2*Cos[3*x] and I need to find coefficients of function ...
1k views

### How to graph a single line plot with different colors based on a value?

I have data that I would like to graph that alternates colors when a condition is identified. For example, say I have the following list: ...
105 views

### Speeding the calculation of a complex polynomial from its roots

Suppose I have a list of (complex, in my case) numbers, and I want to construct the coefficients of the monic polynomial of which they are the roots. The obvious way: ...
138 views

### Extracting the curl-free component of a vector field

I am trying to extract the curl-free component of a discrete vector field. My plan is to take the Fourier transform of the vector field and then extract the radial component in Fourier space. The ...
79 views

### Write Partition of $n$ as an $n$-tuple

I recently asked the question (Computationally Employ Sum over Ordered Partitions?) which I think I can work through. But there's a subtelty I overlooked before that problem is even well-defined, ...
273 views

### How to improve the creation of tables of code and comments

While writing a response to a certain MSE question I made a function that tabulates code and comments. (See the definition below.) Here is an example: ...
72 views

### Computationally Employ Sum over Ordered Partitions?

I have the following function defined, with two inputs $g$ and $h$: ...
174 views

### Generating prime factorizations from an integer's digits by inserting * and ^ into the digit sequence

Problem Given a positive integer, output all possible valid prime-factorization "statements" thereof created by inserting zero or more multiplication (*) symbols and zero or more power (^) symbols ...
159 views

### Add two functions in a table with the same variables

How can I print the values of the function expere in the table of the function exper ... Note that I use this code ...
117 views

### Slow evaluation of large matrix

I have been trying to evaluate the matrix ce[n] in the code below but it is taking too long and still running as you increase n (...
285 views

### Is it possible to extract edges shared between two labeled objects?

For the past couple of weeks I have been trying to implement a cell-tracking and lineage mapping algorithm using which biological cells can be tracked in a time-lapse image. The code can be found at ...
215 views

### Problem generating a cobweb diagram/ visual iteration of a cubic map

With reference to "Non-linear Physics with Mathematica for Scientist and Engineers", I extrapolate the codes for a visualisation of an iterative cubic map but ran into problems. ...
812 views

### How and why to use monadic programming in Mathematica?

This is a methodological question with two parts: How to use monadic programming in Mathematica? Why use monadic programming in Mathematica? In my opinion the questions are inter-related -- we ...
31 views

### Monitor and record ethernet port upload speeds

Can I use Mathematica to monitor and record ethernet port upload speeds? I briefly looked at DeviceStream; not sure if that can be made to work or if that's the ...
52 views

### Definition of the vertical size of the enclosing region in CreateDialog and DialogNotebook

Unfortunately, I am not aware of any options that would allow me to control the vertical size of the enclosing region in CreateDialog and ...
281 views

### Is it possible when creating an exe file from Mathematica code to include functions that create windows? [duplicate]

I'm building a program that uses SQL code to import live data, and uses said data to calculate basic SPC limits. This data is then graphed in a separate window. My final goal is to be able to turn ...
76 views

### Correct arithmetics for CellMargins, CellFrame and CellFrameMargins

When writing this answer I came into trouble trying to calculate total horizontal margins for contents of a cell in the right way. The first part of the problem is that both ...
195 views

### how to make program read from top-to-bottom? [closed]

"As a general principle, make the program read from top to bottom rather than jumping around. Experts agree that top-to-bottom order contributes most to readability." I think it's difficult to do it ...