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
2answers
119 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
71 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
138 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
50 views

Problems with Which statement doesn't evaluate

...
5
votes
3answers
390 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 ...
3
votes
1answer
200 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
97 views

Adding fractions from subsets of variables

...
5
votes
3answers
158 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
32 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
570 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
178 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
121 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
984 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
61 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
176 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
119 views

Do loop and general loop question for updating a variable

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

RSolveValue, Table and general programming

If I have the following code: ...
1
vote
1answer
80 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
149 views

Fletcher-Reeves Method

I'm trying to implement the Fletcher-Reeves Method, the code is: ...
4
votes
3answers
182 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
41 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
69 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
140 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
69 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
97 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
85 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
39 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
145 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
67 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
112 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
52 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: ...
2
votes
1answer
265 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
100 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
80 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 ...
0
votes
1answer
206 views

I have just begun to use mathematica and was hoping someone could help me understand these error codes

" I have an assignment where I am required to use bisection or false position method depending on various inputs and I think I have a reasonable code that should work but I am not sure why I keep ...
3
votes
2answers
89 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 ...
5
votes
2answers
155 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
92 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
39 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 ...
9
votes
6answers
484 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 ? ...
3
votes
0answers
156 views

Calling custom function from C++

I'm programming a project where I use multivariate symbolic polynomials. At some point I need to perform a PolynomialMod over a prime modulus, but the library GiNaC which I use works only over the ...
9
votes
1answer
465 views

Moving B.C.s in heat diffusion model

I came across the paper Solidification dynamics of an impacted drop regarding a heat equations by Thiévenaz et.al and was interested in knowing how they obtained the graphs presented. From what I ...
2
votes
2answers
98 views

Finding the smallest integer such that a given condition holds with "binary search"

Setup. Suppose we are given a function $$f:\mathbb N\to\{\text{False},\text{True}\}$$ such that $$f(n)=\text{True}\implies f(n+1)=\text{True}$$ and such that $f(n)=\text{True}$ for some $n$ large ...
1
vote
1answer
42 views

Function and patterns. FixedPointList doesn't work with function [closed]

There is a function: Clear[sort]; sort[{a___, b_, c_, d___}] := {a, c, b, d} /; b > c; It perfectly works with NestList function: ...
3
votes
1answer
156 views

NextKSizePartition, or how to partition a set into subsets of size $k$ but incrementally

This question might seem very much like the linked one below but it differs in a very special way; Mr.Wizard suggested I start a new post: Partition a set into subsets of size $k$ What I want is to ...
-3
votes
1answer
227 views

How to use deep clones in Mathematica [closed]

Is there a way to use deep clones in Mathematica? Maybe by making lots of different kernels. In order to execute multiple notebooks I need more than one kernel, is there a way to make them using C# ...
-4
votes
3answers
95 views

How to print by using For loop? [closed]

For[mu = 0; mu < 6, mu++, mu = -4.84*10^(-4) - 17.82*10^(-4)*T1 + 1.53*10^(-4)*T1*2.303*Log[T1]; Print[T1]] I want to get the value of ...
1
vote
1answer
47 views

How can I find EdgeWeights strongly connected components using Manipulate

Given the following Code: ...
17
votes
3answers
822 views

Why use \[FormalN]?

Through a copy of some code from an answer on this site I discovered the existence of: \[FormalN] The documentation describes it as follows: ...
1
vote
1answer
110 views

How can I count the number of edges between connected components of a directed graph

The following code: ...

1 2
3
4 5
30