# Tagged Questions

Questions about optimizing code for faster results, or how to do faster computations.

84 views

### Why does the function Evaluate speed up one function by orders of magnitude and another function not at all?

I've got two functions, one sample function (function 1) i've created for demonstartion purposes here, and my actual function. The function Evaluate speeds up the sample function by orders of ...
113 views

### Why does Evaluate fail? [closed]

If i use this code: ...
43 views

### Understanding Mathematica: How to write fast code? [duplicate]

I'm relatively new to Mathematica but have done a few projects using it so I'm quite comfortable with the syntax and the basic functions available. Since I've had programming experience in the past I ...
259 views

### How to speed up minimization of function

I have the fallowing code (the functions within that code are replaced by simpler ones, but the code structure is identical):  ...
89 views

### Speeding up the numerical integration of a certain function

I'm using the following function f[t_] := 3/4 t^-3 NIntegrate[(x^4*Csch[x/2]^2), {x, 0, t}, Method -> {Automatic, "SymbolicProcessing" -> 0}]; I ...
72 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 ...
190 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$: ...
531 views

### Generating an Ulam spiral

An Ulam Spiral is quite an interesting construction, revealing unexpected features in the distribution of primes. Here is a related topic with one answer by Pinguin Dirk, who has provided one ...
392 views

### Speed up ContourPlot3D

I have two issues with the following code. (1) It executes too slowly. If I use "Speed" instead of "Quality" for PerformanceGoal, I get the speed but an undesirable delay in proper rendering of the ...
173 views

### Replacing High Densities of 1.s in Very Large Binary Arrays

I am working with very large binary arrays on the order of {100,100000}. It may look something like this. ...
117 views

### Exp is slower for some number ranges

I get a hit on performance with the Exp function depending on the range of my inputs. for example, with: ...
154 views

### Module in numerical model for NonlinearModelFit is slow and leaks memory

I am trying to make a NonlinearModelFit where the model is the result of a numerical calculation. My code works, but it is very slow and also seems to have a memory ...
144 views

### Speeding up a function

This is un updated version of a previous (now deleted) post of mine. I need to marginalize a distribution. I was suggested to use the code in this thread. This works just fine, but the problem is ...
273 views

### How to efficiently drag points on a curve within a Manipulate

My intention is to demonstrate on any conic various metrics properties on points belonging to the conic and connected by lines. I want the points to be dynamically moved not the usual way, ...
233 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: ...
85 views

### How to save the results in an identical Excel file (.xls) in each iteration of a Do loop

Assume the following code (Below code is just an example to clearly illustrate my problem): ...
115 views

### Garbage collection for memoized functions on subkernels

I have a top-level function which operates on some data: findBestIntegers[data_]:=ParallelMap[optimize,data] which makes parallelized calls to an optimization ...
385 views

### Is there a better way to add elements to a Graphics expression repeatedly?

Consider simple example where a set of points is generated and some are displayed. ...
193 views

### Surface area of intersecting spheres

Given a sphere of radius 1 centered at the origin and $n$ spheres with radii $r_i$ centered at predefined coordinates, $c_i$, in space, I am after the surface area of the unit sphere that is not ...
419 views

### Bresenham's line algorithm

Bresenham's line algorithm is producing discretized line for given two points for purpose of plotting for example. Like that: I have to stress that I'm interested in positions, not a plot. ...
236 views

### DynamicModule/Dynamic CheckboxBar Slow for Large Lists

I am trying to create a dynamic construct that takes a large list of expressions and allows the user to interactively select any number of entries for further manipulation. This is what I have ...
150 views

### Speeding up inversion of symbolic matrices by invoking caching

Is it possible to reduce the computation time taken to find inverse of symbolic matrices USING CACHING TECHNIQUES accessible (if any)? I am trying to compute inverse of symbolic matrices of size ...
64 views

### Is there a faster way to do Normal[SparseArray[{{1,1,1}→1.2, {1,1,2}→20.2, …, {m,n,p}→0.3}]]?

I have a list of the form {{1,1,1}→1.2, {1,1,2}→20.2, ..., {m,n,p}→0.3} and I want to create an $m \times n \times p$ array, $A$, where the value of $A[[i,j,k]]$ is ...
587 views

### Fast way of finding position of Interval containing an Integer

I have a large list (about 2.2 million) of pairs of integers. Each pair defines an Interval[{}]. Given some integer x, I need to ...
135 views

### Simulation code performance tuning

The following simulation takes over 20 seconds for evaluation. I have difficulty re-coding it with Nest and Map or Compile functions to make it more efficient. Can some one help with this? The ...
496 views

### Suppress connection to Wolfram|Alpha when making unit conversions

I want to speed up calculations with unit conversions. I suspect primarily that some units evaluate from Wolfram|Alpha. Any way to prevent this automatically, so that Mathematica throws ...
512 views

### Why is my solution to PE #5 so slow

I'm new to Mathematica and it was suggested to me to go through the Project Euler problems in order to learn it. However, I can't quite figure out why my solution to #5 is so slow. The problem: ...
88 views

### Increase optimization processing speed

As you know, sometimes numerically solving of optimization problems takes several minutes. For this reason 2 question came up to me: 1 - When one is abort the optimization procedure, how it is ...
74 views

### Speeding up Integrate and the numerical solution

I want to compute the drag of a plate Below is the code I am using to integrate the function ...
107 views

### How I can control the speed with which the cone is filled? [closed]

My idea is: By calculating the speed ie VelVol = v2 * t; where v2 is the volume of the second cone (the amount of "water" that is inserted into the cone) You can see that I have 4 slider (The first ...
38 views

### Faster evaluation of an expression for brute force optimization [duplicate]

I'm trying to bruteforce an optimization problem and I want to generate roughly a million function evaluations. I was wondering what would be the best for me to do in terms of having the expressions ...
172 views

### How does the speed of WriteString compare to other languages?

I'm doing something where the most sensible approach seems to be to open a file and write to it as I process data from some large tables. Old school. While testing the program, I remembered the low ...
2k views

### Speed up ordering digit code?

My goal is given an integer number to deduce if its digits increase (or remain the same) from left to right or not. Example: $1236, 123336$ are both considered numbers with increasing digits, but ...
147 views

### Code performance problem

Could anyone help me with the attached code? How would you speed up my attached code in some degree? Your comments are highly welcome. ...
246 views

### What's the best way to generate all the upper triangular matrix whose singular values are given?

For example, given $\lambda_1 = 1, \lambda_2 = 2, \lambda_3 = 3$, what's the best way to generate all the upper triangular matrix ($3\times 3$) whose singular values are $\lambda_i$? Note:Given a ...
182 views

### speed up for computing MatrixExp

My code use two method to computing MatrixExp, I expected the second snippet code will faster than the first one, but in fact it a bit slower than that. How can I ...
200 views

### Modified ListPlot, how to speed it up

I use Mathematica almost every day for several jobs (computations, graphics, etc.). I admit that this software contains much more options (capabilities) than one user may need. Well, not always since ...
90 views

### Plotting a sum as a function of its upper bound

Apologies if this is easy to find in the documentation, but is there a quick way of doing the following up to any given 'n'? ...
330 views

### Slow plotting of trigonometric functions

I have two sets of solutions for a and b. I'm plotting solution only if it is positive for both ...
177 views

### How could I improve this Central Limit Theorem demonstration speed- and content-wise?

My purpose is to demonstrate the Central Limit theorem by assuming two custom distributions, taking some random samples, calculating their means and ploting the results. Ideally, the histograms should ...
171 views

### how to improve efficiency when I want to classify a list according to certain laws

I have a function that generates lists: f[n_] := Join @@ Permutations /@ PadLeft@IntegerPartitions[n]; For example f[3] ...
84 views

### Is there something like MaxProcessorUsed?

For standard procedures it is easy to test if the implementation is better or worse than other by using Timing etc. It does not help us with creating ...
132 views

### How can I speed up my numerical integration?

Here is my code: ...
269 views

### Taking real and imaginary parts of indexed functions and speeding up ComplexExpand

I am setting up a large system of ODEs and in order to use the IDA method (which is sig. faster for my system and thus attractive), I must split my equations into real and imaginary parts. I am ...
132 views

...
135 views

### Better way to evaluate integral containing Boolean function

I am trying to compute the integral ...
220 views

### How to combine two usages of # into one and speed up the code?

I have a function num with two variables, matf and matg. How can I combine the last two lines of code below into one? The code is aimed to find out the maxiaml count bel when we give each \$i3 = ...
173 views

### How to optimize computing a product?

Problem description Write a function to caculate the formula My solutions Solution 1: ...