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
0
votes
0answers
23 views

Problem wiith If statements inside For loop

Consider If statement If[1 == 2, 1] which is false and so does not evaluate, and If statement If[2 == 2, 2] which is true ...
1
vote
1answer
62 views

How avoid to memorize 1 billion useless data

I am a newbie Mathematica user I wanted to know, using brute force, how many non empty triplets $\{A_1,A_2,A_3\}$ of subsets of $$AA=\{1,2,3,4,5,6,7,8,9,10\}$$ satisfy the conditions $A_1\cup A_2\cup ...
0
votes
1answer
51 views

How do I see output for intermediate steps in a program?

I understand Mathematica programs to be a series of steps enclosed in simple parentheses. Each 'step' ends in a semicolon except for the last. The program output is then the output of the last step ...
0
votes
1answer
43 views

TogglerBar linked to Buttons that override input list

This question is about extending the solution provided here. How do I allow the user to change x outside the TogglerGrid function so that the TogglerBar shows the new values of x? I've set it up ...
3
votes
1answer
91 views

Need help with a linear programming problem

Consider $1\rightarrow{}x+2y\leq{500}$, $2\rightarrow{}2x +y \leq{520}$, $3\rightarrow{}2x+5y \leq{}1200$, $4\rightarrow{}x \geq{}0$, $5\rightarrow{}y \geq{}0$, The above is the set of inequalities ...
4
votes
0answers
109 views

What is the best coding style for performance?

The problem of Mathematica is there are too many ways to perform one task. That leads to confusion for new users because the performances of these methods are so different. I'm learning the best ...
6
votes
4answers
271 views

Converting an equation with units to one without units

I may have a solution but it is not slick! See below Doing numerical calculations with functions that use units can be very slow. I would like to have a function or operator that can turn my functions ...
0
votes
1answer
96 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 ...
0
votes
1answer
33 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 ...
5
votes
3answers
319 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. ...
3
votes
1answer
46 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 ...
10
votes
2answers
257 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. ...
1
vote
0answers
51 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. ...
1
vote
2answers
28 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 ...
3
votes
3answers
117 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 ...
1
vote
1answer
49 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 ...
1
vote
0answers
32 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 ...
2
votes
2answers
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$ ...
7
votes
0answers
97 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 ...
0
votes
0answers
21 views

How to terminate NestWhileList when f is applied to a List

I made the following function to demonstrate a Number Theory theorem: ...
1
vote
0answers
38 views

set and set delayed in dynamic programming [closed]

The first one is running Module[{f}, f[1] = f[2] = 1; f[n_] := f[n - 1] + f[n - 2]; f[5] ] But the second one never ends its loop. ...
11
votes
1answer
200 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 ...
0
votes
1answer
80 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 ...
4
votes
3answers
249 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 ...
2
votes
3answers
78 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 ...
3
votes
2answers
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 ...
2
votes
1answer
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: ...
8
votes
1answer
376 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 ...
1
vote
0answers
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 ...
1
vote
1answer
25 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: <...
2
votes
2answers
115 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 ...
3
votes
1answer
87 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 ...
3
votes
3answers
119 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$ ...
3
votes
1answer
94 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 ...
3
votes
0answers
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 ...
5
votes
2answers
92 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 ...
2
votes
1answer
49 views

Implementing binomial expansion of (non-commuting) matrices in Mathematica

Given two matrices $A$ and $B$, their Binomial expansion is, in general, given by (see this page) $(A+B)^n = \sum\limits_{k=0, k=n[2]}^n \Bigg( \sum\limits_{r=0}^k \binom{k}{r} A^r B^{k-r} \Bigg) \...
0
votes
0answers
78 views

FindRoot & Non-negativity constraints

I employ FindRoot to solve a large optimization problem. I formulate the optimization problem in terms of first-order conditions (in that specific problem, methods based on the objective function do ...
0
votes
0answers
41 views
5
votes
3answers
344 views

Writing a program that divide numbers until I hit a one digit number

Well, I have the following question: How can I write a program such that an input number $n$ is divided by the number $k$ as long as the resulting number does not have one digit, if the resulting ...
0
votes
0answers
32 views

Generalization of the nested for loop

...
0
votes
0answers
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 ...
3
votes
1answer
138 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 ...
3
votes
2answers
90 views

Adding fractions from subsets of variables

...
5
votes
3answers
156 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. ...
0
votes
1answer
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: ...
8
votes
1answer
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 ...
7
votes
2answers
154 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: ...
-1
votes
1answer
90 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[1] for this example): ...
7
votes
4answers
250 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. ...

1
2 3 4 5
29