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
8
votes
1answer
317 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
17 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
21 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
109 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 ...
-2
votes
0answers
58 views

Mathematical particle collision problem

There are three types of particles in the container, A, B, and C. If two particles of the same type collide, it will become a B particle; if two particles of different types collide, it will become ...
3
votes
1answer
65 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
107 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
90 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 ...
2
votes
0answers
35 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
82 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 ...
1
vote
1answer
36 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
56 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
36 views
5
votes
3answers
332 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
31 views

Generalization of the nested for loop

...
0
votes
0answers
34 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
120 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
88 views

Adding fractions from subsets of variables

...
5
votes
3answers
153 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
30 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
551 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
144 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
84 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
158 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. ...
0
votes
1answer
45 views

Problem with Do Loop and TableForm

The following code is supposed to generate 10 tables based on different calculations for different q: ...
5
votes
2answers
157 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 ...
0
votes
1answer
28 views

Do loop and general loop question for updating a variable

My intention with the following code: ...
0
votes
0answers
37 views

RSolveValue, Table and general programming

If I have the following code: ...
1
vote
1answer
74 views

General question about programing

If I have the following general excel columns, how could a create a program or loop in which I can generate what I have in column A and Column B as lists. "i" represents row number so that for ...
1
vote
1answer
83 views

Fletcher-Reeves Method

I'm trying to implement the Fletcher-Reeves Method, the code is: ...
4
votes
3answers
163 views

Canonical way to map a function to diagonal elements of a square matrix?

What is the Canonical way to map a function to only the diagonal elements of a matrix? For example, given A = {{E, 0}, {0, E}} I wanted to take the log of the ...
1
vote
1answer
30 views

Manipulate does not work if an equation with a variable parameter is not explicitly written

I have a little problem using the Manipulate command. I am trying to write down the parameter control of a function that is entered into this command not explicitly. But in this case, the variable ...
0
votes
0answers
39 views

Count data fitting with Nonhomogeneous Poisson process

Following is count data needed to model with a nonhomogeneous Poisson process (NHPP). For each row-wise e.g. 8:15-8:30, every 12 intervals of 15 minutes size and 15 days of data collected. I have ...
2
votes
4answers
133 views

How to adress the # Map variable via a function?

How to adress the # Map variable via a function. Consider the following function: sf3[n_,fun_]:=Map[Map[fun[#]&,Range[Floor[n/#]]]&,Range[n]] Now ...
2
votes
0answers
37 views

How to make following feynman path integral simulation [closed]

I want to do the simulation of Feynman path integral which is given in here. How should I proceed?
1
vote
0answers
91 views

How to use Mathematica to find the coordinates of 7 points?

Could anyone please help me with using Mathematica to find the coordinates of 7 equally spaced points on the unit sphere $S^3$ in $\mathbb{R}^4$? Thanks a lot!
1
vote
0answers
67 views

Faster methods for performing repeated list manipulations?

I've done my best to pore over the other posts on this site, and to the best of my ability I can't seem to find a good solution to my problem, so I apologize in advance if elements of my question are ...
1
vote
1answer
33 views

Get all step values from a while-loop

I did a loop (first of my life) for an iterative calculation. Is it possible to get all step values as a matrix. That means the "xValue" variable should be like {215.108,219.688,...} and not only the ...
1
vote
1answer
142 views

Help with solving an equation [closed]

Could anyone please help me find the real solution(s) to a system of equations, or could anyone please help me find an effective solver to solve it? The function ...
2
votes
1answer
29 views

Plot GridLines not displaying

GridLines not rendering. Tried changing Background to White and GridLines to Black to see if they render at all but they do not. How do I make GridLines render and can these PlotStyles and settings ...
5
votes
1answer
89 views

Minimization problem and Voronoi Mesh

I have a random convex mesh $Q$, made of $n$ polygons, and I want to test how close it is to a Voronoi tessellation. In other words, I'm looking for generators (seeds) $\{(x_i,y_i)\}_{1\leq i\leq n}$. ...
1
vote
1answer
47 views

Creating a For Loop to simulate matrix changes

I'm trying to create a For loop (Using the For syntax is a necessity for the future work I'd be performing) for a matrix given by the following lines of code: ...
1
vote
1answer
219 views

Search for squares

Could anyone please help me find $a\left(x,y,z\right)$, $b_{i}\left(x,y,x\right),$$c_{i}\left(x,y,z\right)$ and $d\left(x,y,z\right)$ that are sums of squares of polynomials or rational functions such ...
4
votes
0answers
85 views

Neural network for a simple game?

I'm taking a class that is based on the Mathematica coding language, and we must do a 6-week final project. I am considering coding a neural network for a simple game like 2048, pacman, snake, etc. ...
0
votes
2answers
68 views

How to count outputs in Catch command by using Mathematica

I am using the below command in Mathematica (an example): Catch[Do[i; If[EulerPhi[i] > EulerPhi[i + 1], Print[i]], {i, 1, 100}]] Of course, I would like to do ...
3
votes
2answers
80 views

Sorting a Collection of Lists by Comparing Different Parts

I am looking for a way to use Sort[] to sort a collection of lists by comparing different parts of these lists. For example, sorting by comparing the second part of ...
4
votes
2answers
105 views

TableView: How to change column headings?

I am not even sure whether it is possible. I would like to change column headings of TableView output to letters such as A, B, C etc instead of 1,2,3. Here is an example: ...
4
votes
2answers
75 views

Manipulate lists as function arguments

I am trying to write a Demonstration, which I believe means I must write it as a Manipulate, not a DynamicModule. My question is essentially the same as "Dynamic lists as function arguments", but I ...
2
votes
0answers
38 views

FindFaces on Raspbery Pi [closed]

I think this is an standard question but I did'nt find any new answer since years. I try to use FindFaces on raspeberry pi. This function leads to an error message : opencv not available for raspberry ...
8
votes
6answers
359 views

Brute Force for solving Diophantine equation

I'm trying to solve the following Diophantine equation using Mathematica: $$2^x=5^y+3$$ I have a code,but is very slow. Can we speed up ? ...

1
2 3 4 5
29