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.

Filter by
Sorted by
Tagged with
5
votes
3answers
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 ...
24
votes
4answers
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 ...
2
votes
1answer
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 ...
1
vote
1answer
457 views

Allan Deviation Algorithm

I am trying to write my own Allan Deviation calculator in Mathematica using the definition, $$\sigma(\tau)^{2}=\frac{1}{2M-2}\sum_{i=1}^{N-1}(\bar{y}_{i+1} - \bar{y}_{i})^{2}\text{.}$$ Where the $\bar{...
0
votes
1answer
246 views

Code for Factorial Function

Below I have my code that I created for finding the factorial of a number. The output I am getting when I enter MyFact[5] is ...
4
votes
5answers
518 views

Delete all data points of a specific row if any one column has a string or “NA”

I have ...
0
votes
0answers
24 views

a question about cdf player embedable demonstration [duplicate]

I have now my first application to be exportable as a cdf. If I safeguard as a cdf it works. But if I embed it in an html page It proposes to download the cdf player which is already on my computer. ...
6
votes
1answer
162 views

Extracting notebook history programmatically

I know there is a way to open Notebook history dialogbox using Cell > Notebook History, but since there can be a lot of history the dialog box can run very slowly with lags. Is there a way to get a ...
0
votes
1answer
57 views

Some side problem in a manipulate notebook

Sorry for the length of the code but the question is only on the Manipulate part. Here are some functions to evaluate apportionment methods ...
14
votes
2answers
638 views

3D tree in Mathematica?

Searching the web for information about the affine transformation, I found the one page, which called my attention for the tree that show and is this but unfortunately do not give information about ...
3
votes
2answers
149 views

A nice way to fold a non constant recursive function

The following code works exactly as expected. It constructs the Balinski-Young apportionment method. It is composed of two parts 1) the construction of the Balyski-Young function ...
3
votes
2answers
118 views

curious simplification problem

Consider the following expression: If[x==x, 1, 2] This returns 1, as you might guess. However: If[x<x, 1, 2] Returns ...
1
vote
1answer
92 views

Partial floatification - is it possible?

Suppose, I have a system of equations like 2y[Pi] + 3 y[E] == Sqrt[7] 3 y[Pi] + EulerGamma y[E] == Zeta[3] Now, I want a numerical solution to this, but I don't ...
4
votes
1answer
5k views

Principal submatrix and Principal minor of a matrix

A submatrix of a matrix is obtained by deleting any collection of rows and/or columns. For example, from the following 3-by-4 matrix, we can construct a 2-by-3 submatrix by removing row 3 and column ...
0
votes
0answers
37 views

What are the differences between the following two functions, explaining to a MMA novice? [duplicate]

Obviously the following two functions bring the same results: ...
0
votes
0answers
30 views

Why N[…] Function is opperationg on the index [duplicate]

i have following problem. I have an expression with some variables a[i]. When i use the N[] function in Mathematica i want them ...
1
vote
1answer
35 views

Separating completely independent systems of BooleanCountingFunctions

I have an augmented matrix as a representation of many instances of BooleanCountingFunction[{k},n][vars], and I want to separate it out into many smaller subsystems ...
2
votes
2answers
140 views

The polynomial function changed to a set consisting of terms of polynomial function

I have the following polynomial function $$f= x_{1,2} x_{2,4}+x_{1,3} x_{3,2} x_{2,4}+x_{1,2} x_{2,3} x_{3,2} x_{2,4}+x_{1,3} x_{3,4}+x_{1,2} x_{2,3} x_{3,4}$$ I want to convert the polynomial ...
0
votes
1answer
57 views

Extract the x values that make the two functions values equal

I have two functions for the x variable. I want to extract x values that make the functions equal. (1) ...
1
vote
0answers
356 views

Obtaining Explicit Expressions for Tensor Contractions in xCoba

I Would like to know, how to reduce a general Tensor expression such as Cd[-c][Cd[c][h[-a,-b]]] (D'alambertian of some unknown two component tensor) to an explicit ...
0
votes
1answer
64 views

How to save some variables ( not all )

suppose i have a function a[x_]:=a[x-1]+a[x-2] ;a[1]=a[0]=0 and i want to save the value a[2] (not all a[2],a[1],a[0] like using Dumpsave because by doing that ...
8
votes
6answers
460 views

Remove element from list and store it in variable?

In many programming languages there are functions that remove an element from a set while giving back that element. E.g. I'd like to have a function FetchFromStack ...
0
votes
0answers
33 views

Looking for the equivalent of C's __LINE__, etc

Some languages provide maintainable ways to specify the number of "the current line". In C, for example, one can use the __LINE__ macro. Does Mathematica have ...
2
votes
2answers
254 views

How to set the Precision for a function?

From this answer (19542) to my question I need to add the WorkingPrecision option to RandomVariate for that particular ...
2
votes
2answers
82 views

Improved a code to work once (no need to repeat)

If I have the matrix W size (4 x 4) W = Array[Subscript[a, ##] &, {4, 4}] $W=\left( \begin{array}{cccc} a_{1,1} & ...
10
votes
2answers
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). ...
1
vote
1answer
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 ...
0
votes
1answer
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 ...
0
votes
3answers
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. ...
3
votes
1answer
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 ...
0
votes
1answer
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 ...
6
votes
4answers
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: ...
3
votes
3answers
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: ...
2
votes
0answers
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 ...
4
votes
1answer
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, ...
10
votes
3answers
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: ...
1
vote
0answers
72 views

Computationally Employ Sum over Ordered Partitions?

I have the following function defined, with two inputs $g$ and $h$: ...
3
votes
1answer
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 ...
1
vote
1answer
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 ...
0
votes
0answers
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 (...
10
votes
2answers
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 ...
1
vote
1answer
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. ...
26
votes
3answers
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 ...
1
vote
0answers
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 ...
0
votes
0answers
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 ...
0
votes
0answers
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 ...
4
votes
1answer
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 ...
-7
votes
4answers
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 ...
2
votes
0answers
81 views

Individual programs running [duplicate]

We have a program in one notebook of Mathematica which takes a long time to be done completely. We wish to run other independent short codes (without any overlapping between syntax and commands) in ...
0
votes
1answer
514 views

Is it possible in mathematica to use dynamic names of variables [duplicate]

I have variables in my code following the following notation : theta12, theta13, theta14 etc.. I would check the values of all this variable so I could write an if condition for each theta but I ...