Questions tagged [algorithm]
Questions about algorithms used or which might be used to implement a procedure known by name or loosely but not in detail. The subject of the question may be a procedure mentioned in the literature or a Mathematica built-in function
312
questions
0
votes
0answers
41 views
Fortune's Algorithm (Conditional Step Size in `Manipulate`)
I am trying to implement Fortune's Algorithm. Here is my code so far.
...
2
votes
0answers
72 views
How to show recursive computation graphically?
I am studying the book "Computer Science with Mathematica" from R. Maeder. The following piece of code solves the Knapsack Problem recursively:
...
0
votes
0answers
30 views
Recursive algorithm taking too long
I'm trying to determine the impulse response of a digital filter using the differences equation. However Mathematica is not being able to compute this easily taking way too long. For what I read this ...
8
votes
2answers
191 views
Generate random lines that don't be too crowded between the intersections
It's easy to generate random lines, such as this
...
0
votes
0answers
62 views
What's going on in this Newton-Raphson algorithm?
I'm looking at this post, over on Mathematics SE. I'll summarize here:
A signal with a known velocity, c is emitted by some source. We're given the coordinates of ...
0
votes
0answers
18 views
Diagonalization of Hermitian Matrices vs Unitary matrices
What are the differences involved in diagonalization of large Hermitian matrices and Unitary matrices? (>5000 x 5000)
Mathematica seems to diagonalize Hermitian matrices almost 20 times as fast as ...
0
votes
0answers
40 views
Trying to implement an algorithm to solve a self-consistent Bloch-Schrodinger Equation
I am trying to understand and to implement an algorithm described by Kunimi-Kato in their supplementary material to solve the self-consistent equation below
$$
\left[\frac{\hbar^{2}}{2m}|\boldsymbol{G}...
1
vote
1answer
104 views
How do I decrypt message with RSA algorithm with modulus n = 302446877 and encryption key e 677?
Message: 196512625 25825210 250970710 140420423 22130212 288711674 26343056
Plaintext is grouped in blocks of 4 letters.
What I have so far =(
...
5
votes
2answers
125 views
Modify each element depending on previous elements
I'm looking to see if there's a more idiomatic/concise/neat solution than what I have for this.
I have a list of boxes with heights and I want to stack them; that is, add to each box the distance to ...
0
votes
2answers
105 views
How to write more simple variable-step Runge Kutta algorithm to solve this differential equation?
Here is a case of Runge Kutta algorithm with variable-step size:
...
1
vote
1answer
89 views
Intuitive visual illustration of wrapping percolation criterion
Context:
When studying percolation in finite sized systems, there exist various definitions and criteria for determining when a given system is percolating, i.e. it contains a spanning connected ...
9
votes
1answer
355 views
Help to create a 2D mesh generator (FEM)
I'm working in a finite element mesh generator. I built this function which generates an 8 node mesh (polynomials of order 2) without any interior node:
...
2
votes
0answers
35 views
How algebraic (or more general) expression is represented (memory level, data structure) in Mathematica?
This is not a question about the usage of Mathematica, it is more about implementation. Mathematica is a very huge system, it can provide a series of very advanced operation against a Mathematica ...
8
votes
1answer
202 views
Fast method to calculating signature of a matrix
For calculation of the topological properties of a hamiltonian, sometimes we need the signature of that matrix. This means we only need number of positive eigenvalues. One simple way is to first ...
1
vote
0answers
54 views
Optimal code generation for evaluation of a fixed set of multivariate rational polynomials
Given a set of multivariate rational polynomials, is it possible to find the optimal (shortest or least expensive in some other sense) sequence of arithmetical operations, such that it results in ...
0
votes
0answers
34 views
Nested for loop with variable length
I am new to mathematica and I want to create the set of all n-tuples whose sum is less than a fixed number $N$. My idea would be to do a for loop where I choose first number $k_1$ in between 0 and N, ...
6
votes
4answers
227 views
Faster way to find longest chain of inequalities
I have a list of algebraic expression, all variables are positive, some of them have a specific size relationship.
Such as:
$\frac{(a b+a c+b c)^2}{a+b+c}\leq \frac{1}{3} (a+b+c) (a b+a c+b c)\leq \...
1
vote
0answers
95 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
1answer
242 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 ...
1
vote
1answer
92 views
0
votes
1answer
45 views
All positive integer points up to a certain distance from a hyperplane
I have the hyperplane $\sum_{i=1}^{d} x_i c_i = z$ for $x \in \mathbb{R}^d$, defined by the vector of postivive numerical coefficients $c_i \in \mathbb{R}, c_i > 0$, and the value $z > 0$.
I ...
1
vote
0answers
87 views
How to write Horner's Algorithm in Mathematica? [closed]
The pseudocode we were given is:
Right now I have:
...
1
vote
1answer
125 views
Writing code to produce continued fractions
I have been trying to create a continuing fraction to help prove the theory about any rational number: a/b being able to be written as a continued fraction where the remainders found in the Euclidean ...
2
votes
1answer
172 views
Extended Euclidean Algorithm
I am trying to program the Extended Euclidean Algorithm. Earlier I made some progress past simply generating garbage data. I am supposed to yield two constants s & t that would help compute the ...
3
votes
1answer
74 views
How to access all instances of a defined function
This should have a simple solution, but for some reason I cannot find how to do this.
Let's say I have a "function" where I have defined values (in my actual example I have many instances of this, ...
3
votes
1answer
124 views
Efficiently computing current flow betweenness centrality for graphs
Definitions:
Given a graph $G=(V,E),$ the current flow betweenness is a node-wise measure that captures the fraction of current through a given node with a unit source (s) sink (t) supply $b_{st}$ (1 ...
4
votes
1answer
108 views
Langton's ant algorithm using AnglePath
I would like to implement Langton's ant algorithm using AnglePath. I know there are some MMA implementation on the internet but I would like to implement it myself.
Here is definition of algorithm:
...
1
vote
2answers
67 views
Mistake in recursive algorithm
I am new to Wolfram, and I am trying to make a recursive Archimedes algorithm in Wolfram.
I read documentation and I tried to run this code
...
0
votes
0answers
20 views
2
votes
0answers
132 views
Combinatorics with booleans equations
I have variables $X_i \in \{1,0,-1\}$. Now I add up $m=3$ variables
$$S=X_1 + X_2 + X_3
$$
and want to find all combinations that give me, $S=1$. I can do this with (see this solution):
...
4
votes
0answers
89 views
Steiner Tree Approximation
I am wondering about the existence of Mathematica code to find (approximate) Steiner trees in graphs. I know there are a number of algorithms to do so --- just curious if anyone has implemented any ...
3
votes
1answer
87 views
Sorting a list into “all possible ways” - sorting with incomplete information
Familiar example of sorting objects
I have a list of $n$ "vectors" $\{x^{(1)},...,x^{(n)}\}$ of form $
x^{(i)}=\sum_{j=1}^m c_j^{(i)}x_j,i=1\dots n$, where $c_j^{(i)}$ are
nonnegative ...
6
votes
0answers
101 views
Mathematica's algorithm for FindIndependentEdgeSet? [closed]
Documentation does not mention about algorithm. My guess is Blossom algorithm because I do not know of any better one.
Posting it with hope that someone might know it for sure.
2
votes
1answer
69 views
Creating pairs of non-intersecting set from a given set
Let's say I have a set {a,b,c,d} and I want to create a list of pairs {{a,b,c,d},{}},{{a,b,c},{d}},{{a,b,c},{}},... such that there is no intersection between each pair, and they do not need to use ...
1
vote
0answers
50 views
How does Mathematica find the process parameter? [closed]
I want to know what kind of algorithm is used by Mathematica's Estimated Process.
For example, we can estimate the parameter as follows:
...
1
vote
1answer
108 views
Given a function $f(t,s)$, compute $\max_{t_2\in [0,1]}\min_{t_1\in [0,1]} |f(t_1,s_1)-f(t_2,s_2)|$
Given a continuous and bounded function $f(t,s)$, $t,s\in[0,1]$, I would like to compute
$$\max_{t_2\in [0,1]}\min_{t_1\in [0,1]} |f(t_1,s_1)-f(t_2,s_2)|,$$
for each numeric values of $s_1$ and $s_2$....
2
votes
1answer
70 views
Find critical radius in percolation
I would like to examine the percolation from the left edge to the right edge on random lattice.
Suppose I have a rectangle with N random points on it.
...
2
votes
1answer
218 views
What would be the best implementation of the D'Hondt method of highest averages for allocating seats on party-list proportional representation?
The 2019 European Parliament elections are happening shortly and seat allocation will use the D'Hondt method of highest averages. In order to analyse possible scenarios and results I need a Wolfram ...
1
vote
1answer
69 views
Duplicate RowReduce
Writing:
Ab = {{1, 2, 3, 4, 2},
{4, 3, 5, 6, 3},
{1, 6, 7, 8, 4},
{9, 1, 2, 3, 2}};
RowReduce[Ab]
I get:
{{1, 0, 0, 0, 1/16},
{0, 1, 0,...
0
votes
0answers
52 views
How to exclude some methods?
Can I exclude one or several methods from methods tried by a function?
When we use some 'algorithm-intensive' function, we can often specify whether we want to proceed according to the chosen method ...
2
votes
2answers
1k views
The most efficient algorithm to find all possible integer pairs which sum to a given integer
I wrote a module in Mathematica which finds all possible pairs of integers from a specified list of integers (which can be negative, zero, or positive) which sum to a specified integer m.
The only ...
14
votes
2answers
1k views
Solving “Resistance between two nodes on a grid” problem in Mathematica
In the context of resistor networks and finding the (equivalent) resistance between two arbitrary nodes, I am trying to learn how to write
a generic approach in Mathematica, generic as in an approach ...
0
votes
0answers
67 views
Most efficient way to define evil and odious numbers [duplicate]
A positive integer $n$ is defined to be evil if the number of ones in its binary expansion is even, otherwise it is odious. Now define the function
$$
\begin{equation*}
t(n)=
\begin{cases}
1 \rm{ \...
5
votes
3answers
396 views
Finding the dangling free part of a cluster connecting two nodes
I am trying to learn how to use Mathematica for analyzing graphs, more specifically in the context of connectivity and percolation.
For the sample graph that I have included in this post, we have a ...
3
votes
0answers
165 views
Approximate Nearest Neighbors in Mathematica?
Is there any support for Approximate Nearest Neighbors (ANN) in Mathematica or third-party packages? I'm looking for a good implementation of locality sensitive hashing for applications where ...
7
votes
0answers
241 views
Hopcroft's Algorithm for Minimization of Deterministic Finite State Automaton
Background
Given a deterministic finite state automaton, Hopcroft's algorithm is a $O(n \log(n))$ algorithm for finding an automaton that generates the same language with a minimal number of vertices....
2
votes
0answers
38 views
How to iterate over Orbit of PermutationGroup?
Another day, another permutation group question.
I'm given a g=PermutationGroup[...], and a list l={1, 3, 3, 2, ...}. I know I ...
5
votes
1answer
401 views
Trying to compute the heat capacity for the 2D-Ising model
I'm trying compute the heat capacity $C_v$ out of my simulation for the 2D-Ising model which is given by
$C_v = \frac{\langle E^2 \rangle - \langle E \rangle^2}{T^2N^2}$ ($E$: Energy, $T$: ...
1
vote
1answer
80 views
Defining iterative algorithms [closed]
Assume the iterative algorithm of interest to be as follows:
...