All Questions

Filter by
Sorted by
Tagged with
4
votes
3answers
806 views

How to speed up large double sums in a table?

I am calculating a 3-by-3 matrix whose elements are given as follows: $$ M_{mn} = \frac{1}{N}\sum_{i=1}^N \sum_{j=1}^N (r^i_m - r^j_m)(r^i_n - r^j_n) \tag{1} $$ where $N$ is the total number of ...
1
vote
1answer
92 views

Efficiently define a function as the numerical result of infinite sums

I want to approximate the solution to the following sum, in such a way that I can plot the function for the variable $\phi$, for a fixed value of $\mu$. \begin{equation} f(r(\phi), \mu)=4 e^{-\mu ...
2
votes
1answer
72 views

How to speed up summations with many list callings?

I am trying something similar to the following code with NN as large as a few hundred (at least 100). Now it's very slow and most time is spent on calculating the ...
2
votes
1answer
41 views

Performance Tuning: Construction of Matrix with Summations

I am trying to solve an eigenvalue problem of a large matrix. The issue is that it takes too much time to construct this large matrix. This is the code that I built: ...
0
votes
0answers
52 views

How do I make this summation work faster?

Is there any way to make this summation be faster? I previously had spherical harmonics integration which was taking forever to run How can I do a faster integration? Using math, I tried to use ...
7
votes
2answers
750 views

How to optimize Mathematica code that depends on eigenvalues of big matrices and big sums?

I've been using Mathematica recently to generate some plots of a few functions. I've been able to get it right after a few questions here. The resulting code, which works, is this: ...
3
votes
3answers
329 views

Speeding up the calculation of a binomial sum

Is it possible to speed up this calculation? A[j_, p_, n_] := Sum[Binomial[n, k] p^k (1 - p)^(n - k), {k, 0, j}] Plot[{A[j, 0.5, 12000]}, {j, 0, 12000}] Thanks!
1
vote
1answer
64 views

Sum of part of a list that increases in length

I have a list of numbers whose length increases by 1 for every iteration of a loop. I need to take the sum of the last 5 elements of the list, and if the list's length is smaller than 1 I need to have ...
5
votes
1answer
103 views

Why does this nested sum appear to sleep between iterations?

I have a weird performance problem in a nested sum, which I've reduced to the following test case: ...
3
votes
2answers
142 views

Faster sum of products of tuples?

My function: sumprob[lst_,size_]:=Sum[Product[x,{x,part}],{part,Tuples[lst,{size}]}]; Example: ...
3
votes
2answers
457 views

Speed up double summation

Is there any way how to speed up this double summation? ...
5
votes
1answer
134 views

Why is summing 1 million slow? [duplicate]

I was playing around with Sum and noticed that summing all integers from 1 to a million is order of magnitudes slower than summing other numbers ...
1
vote
0answers
43 views

Error with Parallel Calculation on Large Multiple Sums [closed]

I am attempting to complete the following quadruple sum: ...
0
votes
1answer
108 views

Accessing the elements in a table is slower than calculating each time?

This is a follow-up of How to accelerate combinations and sum calculations here? I have tried all tricks but when N reaches 35 the time is still intimidating in a 16-core server, which is far better ...
2
votes
1answer
145 views

How to accelerate combinations and sum calculations here?

I have a 4d matrix H defined as below (embedded with combinations and sums) ...
3
votes
1answer
321 views

Speed up computation of sum from large matrix

I have a 3x3 matrix (252^3) of data (densities) and I want to compute a correlation xi from nearest neighbours as well as a sum involving a check whether the density is in a certain bin. The ...
3
votes
2answers
202 views

Summing matrix products

I need to compute a double sum over a weighted matrix product: $L[M]=\sum_{i,j}^{N}\Lambda[[i]]\;\omega[[i]].M.\omega^{\dagger}[[j]]$. $\Lambda$ is a list of with N complex values(weights) and $\...
5
votes
2answers
341 views

Speed-up the computation of this sum of small matrices

Given a matrix mat with a large number of rows (a few thousands) and a few columns (between 2 and 10), I'd like to compute the sum of the "small" matrices obtained ...
0
votes
1answer
403 views

Slow sum computation

I'm doing a simple OLS regression and I strikes my attention that this very simple computation takes several seconds to perform in Mathematica ...
4
votes
1answer
464 views

How to increase the evaluation speed of this somewhat complicated table / matrix operation?

I'd like to calculate the following one-dimensional array: OneDimArray = Table[(Norm[Sum[ MatrixA[[i,j]]VectorB[[j]],{j,N}]])^2,{i,N}] However this takes a very ...
2
votes
0answers
76 views

Follow-up to “How to differentiate formally?”: Efficiency concern

In link to "how to differentiate formally?" and particularly to the answer by @Jens, I want to do something like this: ...
1
vote
2answers
115 views

How can I speed up this code with 4 variables sum

I have to make a sum over 4 variables. My code is very very slow. I want to know how to speed up this code. This problem is related to but different from one previous problem. Any help or suggestion ...
14
votes
2answers
455 views

Fastest way to sum the upper triangle

I feel like this is an recurring question: if there's a symmetric matrix whose diagonal is not all 0, how could I get the sum of the part of it that's above the diagonal as fast as possible? Small ...
5
votes
2answers
308 views

The fastest way of raising indices of high rank tensor

I have some high dimensional high rank tensors, let's say $$F_{ijkl}$$ and I need to find $$F^{abcd}=g^{ai}g^{bj}g^{ck}g^{dl}F_{ijkl}.$$ Here $g^{ij}$ is the contravariant metric. Simple summation ...
1
vote
0answers
124 views

Improve speed of evaluating a sum over four indices

I am trying to implement the Fox-H function with several variables as sum of residues. I have arrived at the following function; ...
3
votes
0answers
97 views

Decrease computation time of module [closed]

I need to compute the exponential of a matrix (in this caseR) by the summation method where R is a square matrix with symbolic ...
3
votes
3answers
550 views

fastest way to perform the following summation

I have a vector $A$ with components $A_{i}$, and two matrices $X$ and $Y$ with components $X_{ij}$, and $Y_{ij}$ respectively. What is the fastest way of performing the following summation $$A_{i}A_{...
0
votes
0answers
66 views

More on performance of Sum[]

There is an interesting discussion on performance of Sum[] in this question. I actually wanted to reproduce findings from this answer. So, I entered: ...
12
votes
3answers
516 views

The speed of Sum[] varies strangely

I was curious about the difference in speed between Total and Sum. I found out Total was ...
22
votes
3answers
480 views

sudden increase in timing when summing over 250 entries

I see a sudden increase of Timing by a factor of thousands when I sum over 250 elements of a matrix rather than over 249. So for instance, this table contains sums ...
1
vote
1answer
110 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'? ...
5
votes
2answers
194 views

Speed up plot of $\sum_{j\ge1} 2^{-j}(1-2^{-j})^{n-1}$

I'm a beginner at Mathematica. I would like to plot the following function: $${n\over2} \sum_{j\ge1} 2^{-j}(1-2^{-j})^{n-1}$$ However the following code is just too slow: ...