All Questions

Filter by
Sorted by
Tagged with
8
votes
6answers
306 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 ? ...
2
votes
2answers
71 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 ...
2
votes
0answers
78 views

How can I make this “Pick” inside a “Table” run faster?

I am working on becoming more and more familiar with MMA and on a scale from one to ten, I would rate myself as a four or a five. I understand vectorization and that loops-are-very-bad. I have ...
16
votes
2answers
315 views

Improving Performance of an XY Monte Carlo

I normally write my Monte Carlo codes in Fortran for speed, but I was doing some quick and dirty work and wrote one in Mathematica for the XY model on a square lattice (see Kosterlitz-Thouless ...
3
votes
3answers
91 views

Efficient manipulation of Associations passed to functions, how-to? [duplicate]

I have some data wrapped into a MyData[data_Association] "structure". My Association contains some big arrays and I do not want ...
1
vote
0answers
33 views

A newbie question about the use of the FourierSeries functions

Although I have had no previous experience with the Mathematica Fourier Series functions ( or package ), I am writing a tutorial on Fourier Analysis and Transformations in a Mathematica Notebook, ...
9
votes
2answers
251 views

Finding the path in a graph from A to B then back to A with a minimum of shared edges

the problem is to find cycle from A to B back to A, so that the path B-A would use minimum edges from path A-B. The graph is undirected and can have cycles. The paths don't have to be shortest, they ...
0
votes
3answers
110 views

Check if number is in list

I have a nested list, but don't know how long the individual lists are. Sometimes they may be 2 numbers long sometimes 1000, so i need to check if theres is a number at position 6 but i doesn't ...
2
votes
0answers
53 views

Fold/ NestList/ etc in MCMC loop for optimisation

I am trying to simplify and optimise an old loop code I wrote. Since Fold and NestWhile use the results of the last iteration in the new iteration, I would like to use them in order to get rid of Do ...
9
votes
3answers
1k views

Speed up code to numerically simulate a game of coin tossing

Description I would like to simulate n games in which two players toss one coin each at the same time: If you toss a tail you will receive two tokens, if you toss ...
1
vote
3answers
141 views

Computation performance involving multiple numeric integrals

I have the following code that has been running for more than three days without an answer, unfortunately. Now, my institution provides us with a computer with Intel Xeon CPU E-52650 v3 @ 20 CPU, 2....
3
votes
3answers
177 views

Generating lists of integer numbers with two constraints

I am looking for an effective way to generate all lists of non-negative integer numbers $\{k_0,k_1,k_2\dots\} $ such that $$\sum_{i\ge0} k_i=K, \quad\sum_{i\ge0} i k_i=N $$ for given $K$ and $N$. The ...
7
votes
3answers
438 views

How can I create an enumeration variable by groups?

I copied the title and concept for this question from here. I have ...
2
votes
2answers
82 views

Improved a code to work once (no need to repeat)

If I have the matrix W size (4 x 4) W = Array[Subscript[a, ##] &, {4, 4}] $W=\left( \begin{array}{cccc} a_{1,1} & ...
3
votes
3answers
105 views

Speeding the calculation of a complex polynomial from its roots

Suppose I have a list of (complex, in my case) numbers, and I want to construct the coefficients of the monic polynomial of which they are the roots. The obvious way: ...
0
votes
0answers
117 views

Slow evaluation of large matrix

I have been trying to evaluate the matrix ce[n] in the code below but it is taking too long and still running as you increase n (...
9
votes
2answers
650 views

Optimizing Mathematica Code

I have implemented the whole Baum-Welch Algorithm for training Hidden Markov Models as described in Rabiner's paper Here is my code that calculates the Forward Probabilities` ...
15
votes
2answers
417 views

Fastest way to combine pre-sorted lists?

I need to combine two long, already-sorted lists into one sorted list. My effort below takes advantage of the fact that the lists are already sorted; but it's far slower than just using Join and Sort,...
6
votes
6answers
318 views

Generate lists with a constraint

I have just started using Mathematica, therefore please excuse possibly stupid questions. I need to generate a list of specific distributions of $k$ ordered objects into $n>=2k$ cells, such that ...
1
vote
2answers
166 views

Print Bingo cards with at most n elements in common by row

Starting from the @MarcoB's solution, I wrote: ...
5
votes
1answer
174 views

How to avoid AppendTo when computing similarities

I need to make the calculation of the HammingDistance for strings faster. The background is that I want to be able to compare the similarity of images of a textual ...
1
vote
2answers
252 views

Out of memory in a Do loop

I have the following code: ...
2
votes
1answer
126 views

Speeding iterative computation

I want to get the following iterative sequence ...
1
vote
1answer
198 views

Speed Up Sampling of Perimeter of Polygon

I have a polygon whose vertices (points) are defined by some image coordinates that I have manually selected. The polygon is used to create a mask for a region of interest in a microscopy image. ...
21
votes
1answer
528 views

Is there a linter to help write good Mathematica code?

I don't do much real programming, but I've recently been turned on to Atom, which has linter plugins for over 50 languages to make coding easier (most drawing on pre-existing lint-like programs). In ...
14
votes
1answer
875 views

Fast implementation of Metropolis-Hastings update with multiple sets

This is an optimisation question rather than something I am unable to do. I have a naive, primitive working version of the code (I submit it below) but I am trying to make it work faster. I am asking ...
2
votes
1answer
96 views

Code optimizations with functions inside Module

I wrote a small code by using functions inside Module: ...
6
votes
1answer
212 views

How to optimize my own BezierFunction?

A few months ago, I asked a question about the implementation of Bezier surface. Please see here for a full detail. I also know that BezierFunction[] is built-in ...
8
votes
2answers
512 views

Implementation of tensor product formula

For the Bézier surface, which owns the following matrix definition: $$\begin{align*} \mathbf S(u,v)&=\sum_{i=0}^m \sum_{j=0}^n \mathbf P_{i,j} B_{m,i}(u) B_{n,j}(v)\\ &=\small \begin{pmatrix}...
3
votes
2answers
87 views

union several arrays of same flag(date for example) efficiently

Suppose I have several arrays from data files which look like: arrayi = {{datei1, xi11, xi21, ...}, {datei2, xi12, xi22, ...}, ..., {datein, xi1n, xi2n ,...}} ...
3
votes
1answer
166 views

Efficiently generating plots from lists of differing lengths

I guess this is more of an informatic question. A quite complicated function of mine generates me a list of valid points, depending on a parameter, like this: ...
11
votes
1answer
360 views

How to implement a more efficient inverse triangular recursion?

Consider the following inverse triangular formula $$\left( \begin{array}{ccccc} & & & & N_{i-p,p}\left(u_0\right) \\ & & N_{i-2,2}\left(u_0\right) & & ...
4
votes
2answers
181 views

Clean & efficient bounding box non-intersection test

I would like a quick test to tell me that segments $ab$ and $cd$ cannot intersect in the plane. If the maximum $x$-coordinate of $a$ and $b$ is less than the minimum $x$-coordinate of $c$ and $d$, ...
2
votes
1answer
185 views

How to determine whether an expression can act as a “good” function?

It's not easy to see whether an expression can act as a "good" function. A good function refers to an operater that transforms symbolic entities like 1+x^2 or ...
10
votes
1answer
987 views

Reap, Sow with Parallelize: bad performance, why?

I have a question about the performance of Reap and Sow with Parallelize. I am aware of the following questions How to collect result continuously (interruptible calculation) when running parallel ...
4
votes
1answer
240 views

How to further accelerate arithmetic with Fermat Pseudoprime and Fibonacci number

I've been working on this all night, and I have made this go pretty fast, compared to my first iteration of the program, but now I'm out of ideas. I'm trying to write a program to test (by good old ...
8
votes
3answers
364 views

How to speed up auxilary DoolittleDecomposite function?

The Doolittle Decomposition algorithm as below: $$A=LU$$ where $A= \begin{pmatrix} a_{11} & a_{12} & \cdots a_{1n}\\ a_{21} & a_{22} & \cdots a_{2n}\\ \vdots & \vdots & \vdots ...
9
votes
2answers
563 views

Relaxation of Mass-Spring System with Pinned Masses

Problem Assume that four masses are connected to each other by springs while two of them are pinned down at their initial positions. Find the position of masses when system is at its minimum (...
2
votes
0answers
124 views

How to efficiently find parts of a string with beginning and ending specified?

I'm trying to find specific URL addresses from a html document. The addresses can be found between the strings "href=\"" and "\" class=\"listing". The problem is not including strings like this: "href=...
2
votes
1answer
196 views

How to speed up my code about Divisors?

This code is about PE496 In[21]:= ParallelSum[n*Count[Divisors[n^2], a_ /; n < a < 2 n], {n, 1, 10^5}] // AbsoluteTiming Out[21]= {5.987342,10724527832} I ...
14
votes
3answers
1k views

Collatz optimization

I'm VERY new to Mathematica programming (and by new I mean two days), and was solving Project Euler question 12, which states: Which starting number, under one million, produces the longest [...
15
votes
1answer
424 views

Why does this line increase the consumed memory?

Probably this is a simple question, however I really don't understand this behavior in Mathematica. It particularly leads to a memory leak in a huge program I have to do processing of 3D images. I ...
4
votes
1answer
134 views

Slowdown of Flat attributed function

I was trying to write an associative function f using the attribute Flat. ...
2
votes
1answer
191 views

How to handle Indeterminate TimeConstrain

I have to use Timeconstrained[aux] first for avoid some bigs calculation that dont need and it use a lot of time of calculate, so i can't do this. ...
4
votes
2answers
731 views

Colorize Grayscale Image

I have a grayscale image that contains two objects. The grayscale pixel values can be divided into three intervals where two of them represent objects and the third represents the background. The ...
19
votes
5answers
2k views

How to speed up my Project Euler code

The evaluation speed of Mathematica often depresses me. It did it again when I wrote a code to solve a Project Euler problem. https://projecteuler.net/problem=206 Here's my code: ...
25
votes
1answer
566 views

Can code optimize code?

Are there functions, programs or packages that deal with optimizing mathematica code i.e. re-writing ineffecive or convoluted code. -This question has haunted me since I joined SE. The background for ...
0
votes
0answers
92 views

Timing Differences

In More efficient implementation for comparing coefficient lists in a Do-loop link, george2079 posts in his first answer a piece of code that takes 352 seconds to compute. When I run this same piece ...
1
vote
2answers
249 views

More efficient implementation for comparing coefficient lists in a Do-loop

I'm wondering how to speed up the following code so it actually computes for $n=2$: ...
5
votes
3answers
286 views

Split list of states by run lengths and discontinuous changes in state

I was asked to look into writing some simulation code for a user, where the simulation output (x) would oscillate between three possible states: ...