# 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,428 questions
Filter by
Sorted by
Tagged with
90 views

### Exporting a multi excel files into one file

Suppose a list of students'grades in excel: "excel files" I want to write a program separate student grades to their respective classes and then write them in one excel file. What should I ...
28 views

### How to load a function from an external notebook that creates a docked cells toolbar?

I coded a compact toolbar in its own file nbtaskmate.nb for various common notebook tasks which I would like to load onto any notebook I might have open with a ...
273 views

### Stacked time series plot

I have multiple time series measured in different units. I want to have a stacked plot of my data with a common x-axis. An example would be here. For illustration, here is my data. ...
45 views

### Generating set of equations of varying length and solving them

I am trying to generate a set of equations that describe a change in density for each variable in the form of: $\frac{dX_i}{dt}=X_i(r_i-s_iX_i+\sum_{j=1,j\neq i}^na_{ij}X_j)$ where n is the number of ...
246 views

### How can I plot my financial indicator below a trading chart (produced by TradingChart) with the same x-axis?

Since this question was not answered, I would like to ask again with some additional information. I have a trading chart saved as chart1 as follows. ...
50 views

### Can Mathematica warn you about mistyped variables?

In other dynamical programming languages like Python, mistyping a variable, e.g. mistyping var1 as bar1 in the example below, immediately results in an error. ...
26 views

### Code to Expand Symmetric Laurent Polynomial in Symmetric Basis

Let $F(w,y)$ be a symmetric Laurent polynomial. By this I mean the powers of $w,y$ are bounded above and below, and $F$ is invariant under $y \to y^{-1}, w \to w^{-1}$. Given such an $F$, there are ...
116 views

### How to simulate the roll of 3 or more dice and ask for a sum of 3 or more?

How to simulate the throwing of 3 or more dice and ask for the sum of 3 or more and indicate the number of calves, or more that are produced. For example if you throw 3 dice, how many cases will add ...
46 views

### How to emulate statistical command choice tab of this widget?-how to do what i ask?

I designed this little program, but I want you to be able to choose what I want to look for by choosing it as you do with the widget tab, please help me. widget Widget of internet my program ...
30 views

### Adding a module to teach Mathematica the Laplace transform of particular Mittag-Leffler functions

Mathematica 11.3 is not aware of a useful Laplace transform LaplaceTransform[t^(-a) MittagLefflerE[a, a, t^a], t, s] which for ...
71 views

### How to program combinatorics problems about randomly moving cards from $A$ to $B$ to $C$ to $A$?

I have a lot of problems with the following scenario, for example, Given 3 boxes $A$, $B$ and $C$. The box $A$ contains 2 identical cards $x$, 4 identical cards $y$ and 1 card $z$. The box $B$ ...
92 views

### Reboot of Maeder's “Programming in Mathematica”, an appeal [closed]

I have been using Mathematica since Version 1, and to me the touchstone for best practices in Mathematica is Roman Maeder's "Programming In Mathematica". It is not fair to say that PIM is ...
20 views

### How to terminate NestWhileList when f is applied to a List

I made the following function to demonstrate a Number Theory theorem: ...
45 views

### Why do I now get a Compile:nogen message, when I didn't seem to previously? [closed]

After some two years since its posting, I just tried implementing the code given in the first answer to Can I use Compile to speed up InverseCDF? I get the message which I don't recall getting ...
36 views

### set and set delayed in dynamic programming [closed]

The first one is running Module[{f}, f = f = 1; f[n_] := f[n - 1] + f[n - 2]; f ] But the second one never ends its loop. ...
196 views

### Solutions for searching over Mathematica notebooks?

I have hundreds of Mathematica notebooks accumulated over the years, and I'd like to search over them. I've been using various versions of text search (grep, SilverSearcher, Spotlight), but there are ...
78 views

### How to show the map of a complex function ( plane z incl the basic square grid to plane w?

I want to make a presentation of the maps of the standard complex functions, as well as some mobius transformations and special complex functions. I want to present it exactly like it is done in the ...
243 views

### How to programmatically modify a function definition

I would like to know an efficient method (without converting Mathematica Code to strings and string processing) of modifying a function definition programmatically. For example, I would like to tidy ...
77 views

### Strange Behavior of Compile[] inside With[]

Consider, in the examples below, the difference between defining $n$ as a global variable or as an argument to function comp[], which includes a compiled function ...
180 views

### How to link Manipulate to specific questions to activate sliders

I have the following multiplication Manipulate: Manipulate[ x*y, {x, 1, 10}, {y, 5, 15} ]; When you run ...
120 views

### Using functions instead of lists in physics numerical problems

I'm using the following code for calculation of reflection and transmission coefficients through square well potential: ...
371 views

### Why are more highly nested lists often not more memory and time-intensive?

I would expect more highly nested lists, being deeper and more complex than flatter lists, to take up more space (bytecount) and take more time and memory to operate on in general. Consider the ...
18 views

### Question about AsymptoticEqual[nChebyshevPsi[x], x, x -> Infinity]

Given the partial sum function nChebyshevPsi[x_] := Sum[MangoldtLambda[y], {y, x}] I would like a True response from ...
24 views

### Defining an iterated differential operator with compositions

I'm a bit new to Mathematica so this question might be a bit basic. Still, I could not find an answer. I wish to define a symbolic differential operator. Currently, I do something like the following: <...
113 views

### How to program a situation like the following in mathematics and generalize the process to other configurations?

Distribute the numbers from 1 to 10(view image) so that the sum of each row and each column is the same and a) the maximum possible b) the minimum possible (I put it from 1 to 10 for ease) I know it ...
85 views

### How can I iteratively add elements to a list

Basically I want to make a histogram with a list of dates by using DateHistogram[]. However I have the data of the dates in nested list format, with elements like ...
116 views

### How can I solve a Set Cover problem in Mathematica

I have $n$ non-empty possibly non-disjoint sets $S_i$, each having a cost $c_i$, and the union $\Omega=\bigcup_{i=1}^{n}S_i$. How can I find a selection of $S_i$ such that the union is also $\Omega$ ...
93 views

### What are some debugging helpers or tips/tricks in your Mathematica toolbag?

I am a novice so imagine my confusion with Mathematica's very poor error and trace messages. Debugging should be an easy thing to do even for beginning programmers but not with Mathematica. What are ...
39 views

### What built-in functions have bad time/space complexity and their alternatives?

It's surprising that Join is $\mathcal{O}(n)$ (due to copy) while I've been using it as a convenient way to join lists together. It also reminds me of suggestions ...
89 views

### Customized priority function in DataStructure[“PriorityQueue”]?

I'm using Mathematica 12.1. The documentation for DataStructure["PriorityQueue"] claims that, ... the highest-priority element is always returned. The ...
49 views

32 views

...
35 views

### ComplexExpand in Module doesn't work as it should, when there is function at the left

I'm new with mathematica and I'm having a problem. I hope you can help me. I made a module to built a system that I can use to find some condition for given polynomial is a Shur polynomial. (Actually ...
133 views

### Help coding an Abelian Sandpile

I'm attempting to code an abelian sandpile. I thought a good way to go about it would be utilizing recursion, which I've never tried in MMA before. The code currently runs but doesn't seem to work (it ...
90 views

...
155 views

### Trying to build a sequence of logical statements ||

I need to build a sequence of n conditions separated by ||. Something like, f = #1===f1[#2] || #1===f2[#2] || ... || #1===fn[#2] & where the number n (integer, of course) is not fixed. ...
31 views

### A problem with Cases and Pattern recognition: unexpected behavior

I need the following command (to isolate exponents and variables): F[X_] := Cases[ X , G[x_]^m0_. -> {x, m0}] This example gives the correct answer: ...
557 views

### Why does Mathematica ignore 1 as an exponent? Or as a coefficient?

Two different examples of same problem: In: Cases[{f^2, g^3, k^p, h}, x_^n_ -> n] Out: {2,3,p} # The result misses the ...
151 views

### Defining a function which is numerical on all vectors of arguments

There is an attribute NumericFunction in Mathematica that can do the following job: ...
88 views

### Problem using TableForm and Do loops

The following code is supposed generates a table based on different calculations for a given q (e.g. q for this example): ...
212 views

### How to rearrange a Matrix elements such that all diagonal elements are non zero?

I'm trying to rearrange a matrix such that all the diagonal elements are non zero.I'm not sure how to proceed. Any suggestion are highly appreciated. ...
47 views

### Problem with Do Loop and TableForm

The following code is supposed to generate 10 tables based on different calculations for different q: ...
163 views

### Code to emulate what excel does in cells

I would like to generate a code which emulate the calculations that are being perfom in columns A and B and row 7 to 12 in the attached first image. The results of those calculations are those shown ...
38 views

### Do loop and general loop question for updating a variable

My intention with the following code: ...
38 views

### RSolveValue, Table and general programming

If I have the following code: ...