# Tag Info

10

Note that Mathematica can do the symbolic sums: Sum[1/(x^2 + 1), {x, 1, Infinity}] gives $$\frac{1}{2} (-1 + \pi \coth[\pi])$$ and Sum[1/(x^2 + x + 1), {x, 1, Infinity}] gives $$-\frac{i \left(\psi ^{(0)}\left(1+\sqrt[3]{-1}\right)-\psi ^{(0)}\left(1-(-1)^{2/3}\right)\right)}{\sqrt{3}}$$ (where $\psi^{(0)}(x)$ is PolyGamma[0,x], and in fact ...

10

Accumulate is absolutely the most idiomatic and appropriate answer here. However since Mathematica is very powerful at list manipulation, it might be illustrative to show you couple of other ways of doing the same thing, just so you learn to think outside of mainstream procedural ways. 1. Using FoldList: This is a functional way of doing exactly what you ...

9

You can use Defer to see how to properly enter your "summation" type notation. Defer[1 + Sum[Sum[1/((k + 2) k!), {k, n, Infinity}], {n, 0, Infinity}]] You can then enter that output to see that it works. You must've entered something different.

9

Instead of creating a list of all tuples and then selecting those whose total is n-1, you could start with the IntegerPartitions of n-1, pad them to length n with zeroes, and create all the permutations: getvecs[n_] := Flatten[Permutations[PadRight[#, n]] & /@ IntegerPartitions[n - 1], 1] I would also suggest using Position for the support function: ...

8

Here is the simplest answer: sum[n_] := Sum[i x[i], {i, 1, n}] x /: D[x[i_], x[j_], NonConstants -> {x}] := KroneckerDelta[i, j] D[sum[n], x[2], NonConstants -> x] $\begin{cases} 2 & n>1 \\ 1-n & \text{True} \end{cases}$ The trick here is the use of the NonConstants option of the derivative operator. This then has to be ...

8

If we transpose the indices of $v$ and $w$ so that $v'_{abe} = v_{aeb}$ and $w'_{ecd} = w_{ced}$, then we can compute $u = v' \cdot w'$: u === Transpose[v, {1, 3, 2}] . Transpose[w, {2, 1, 3}] (* True *) We can use a similar trick to compute $q$ if we reorder $v_{dea} \to v''_{ade}$, except that this time the $d$ and $e$ indices in $v_{ade}''$ and ...

7

There are several methods in Sum which may help in various cases. To find your second sum symbolically in apparently real form you can try, e.g. Sum[1/(1 + x + x^2), {x, 1, Infinity}, Method -> "HypergeometricTermPFQ"] However there are still other ways to get the same result without methods specified, e.g. : s = Sum[1/(1 + x + x^2), {x, 1, ...

7

If your elements are in lists the fastest way is to use array operations. In the present case of an outer product one index, let's say "i", will not be expanded, on the other you want to thread. To operate on a list the function needs the attribute Listable. The Times function, as many other internal ones, is already listable, that is Times[{1,2,3},x] = ...

6

If you know in advance that your sum is already convergent, you can skip the convergence check. Also, it sometimes helps to change the Method used by NSum[]. Here, I use the Shanks transformation as the summation method: Plot[n/2 NSum[2^(-j) (1 - 2^(-j))^(n - 1), {j, 1, ∞}, Method -> {"WynnEpsilon", Degree -> 2, "ExtraTerms" -> 30}, ...

6

First of all, as you seem to indicate, you don't have the problem with accuracy if you use := (SetDelayed) in your function definitions instead of = (Set), although, as you say, with this change it takes longer to evaluate f. The accuracy improves because Mathematica will calculate the Hermite polynomials accurately when x is Real. Using Set for the ...

6

Since the sum goes over the last index of $e$ and the first index of $A$, it is directly done by using Dot: dim = 5; e = Array[\[ScriptE], Table[dim, {dim}]]; a = Array[\[ScriptA], Table[dim, {2}]]; c = e.a; Here I defined the arrays with the appropriate dimensions but suppressed the output because it's too long for five dimensions. Another ...

5

Since If has attribute HoldRest, the i will not be inserted into the latter parts during the evaluation. Consider this example showing the same effect: Sum[s[i, Hold[i]], {i, 1, 2}] (* s[1, Hold[i]] + s[2, Hold[i]] *) I think the best practices way of getting what you are asking for is to use With to ensure i gets inserted: Sum[With[{i = i}, If[x[i] < ...

4

I did some computation of formal derivatives a while back which might be of interest in this context (though keep in mind that this is anything but bullet proof!). Clear[a]; Format[a[k_]] = Subscript[a, k] Let us say we have an objective function which is formally a function of the vector a[i] Q = Sum[Log[Sum[a[r] Subscript[B, r][Subscript[x, i]], ...

4

In Mathematica version 9, you can do these kinds of things much more naturally. Here are the two quantities that you wanted: u = TensorContract[TensorProduct[v, w], {2, 5}]; q = TensorContract[TensorProduct[v, w], {{1, 4}, {2, 5}}]; The contraction is performed on the tensor product in which the first three indices belong to the factor v and the last ...

4

The problem has to do with precision in numerical approximations. During the evaluation of your function Mathematica has to deal with really huge numbers, so you have to make sure that during this computation everything is evaluated up to a very high precision. One way to achieve that is by specifying the initial argument with high precision. For example, if ...

4

You seem to be writing a tortured definition. As already commented you need Pattern in the left-hand-side of the definition. There are better tools than For in nearly all cases. Return is misapplied and unnecessary. As far as I can tell Total is dropped into the middle of things with no particular consideration. You probably want something like this: ...

3

Just for fun, here's a recursive approach: accSum[{}] := {}; accSum[{x_}] := {x}; accSum[{r___, x1_}] := Join[{Total[{r, x1}]}, accSum[{r}]]; Usage: list = {11.5575, 11.397, 5.52734, 4.0878, 2.54815, 1.86652, 2.55028, 2.14952, 1.6242, 1.34117} accSum[list] // Reverse Gives: {11.5575, 22.9545, 28.4818, 32.5696, 35.1178, 36.9843, 39.5346, 41.6841, ...

3

This is an approximation, but the result is immediate calculating over the integers: f[n_] := Sum[2^(-j) (1 - 2^(-j))^(n - 1), {j, 1, Infinity}] DiscretePlot[n/2 f@n, {n, 1, 101}, Joined -> True, PlotRange -> {0.72, 0.724}]

3

number = 3 E^(5 I x) + 10 E^(7 I x) + 2 E^(1 I x); abs = ComplexExpand[Abs[number], TargetFunctions -> {Re, Im}]; arg = ComplexExpand[Arg[number], TargetFunctions -> {Re, Im}]; abs E^(I arg) it gives : $e^{i \text{ArcTan}[2 \text{Cos}[x]+3 \text{Cos}[5 x]+10 \text{Cos}[7 x],2 \text{Sin}[x]+3 \text{Sin}[5 x]+10 \text{Sin}[7 x]]} \surd \left((2 ... 3 The sum is a little strange, because the multinomial coefficient makes sense only when$k_1+k_2+\ldots+k_n=m$. I will assume this restriction is (implicitly) intended and that$n$is fixed. (If not, a variation of the following solution will work.) Notice that the set $$\{0 \le k_1 \le k_2 \le \ldots \le k_n \le m\}$$ is in one-to-one correspondence ... 3 The crucial point is that N@Sum is not NSum. What N@Sum is N@Sum will first try to evaluate the sum symbolically and then approximate it numerically. Only if Sum cannot perform the first task, and then returns (at least partially) unevaluated, N will resort to using NSum. In case of a finite sum, Sum will always return an evaluated result, consisting ... 2 This is apparently a problem of version 8 where I get the same. In version 9.0.1 I get (1/(n! Gamma[ n]))(-n! (5 n^n + E^n (1 + 4 n) Gamma[n] - E^n Gamma[n, n] - 2 E^n Gamma[1 + n, n]) + n^n Gamma[n] HypergeometricPFQ[{2, 2, 2}, {1, 1, 1 + n}, n]) or, with nicer formatting, This can be reduced with Sum[((n - y - 1)*(n - y)^2*n^y)/y!, {y, 0, n - 2}] ... 2 The formula is a little vague because starting limits for the$n_i$are not given. However, its form suggests it started out as $$\sum_{(n_1, n_2, \ldots, n_k) \mid 1 \le n_i \wedge n_1+n_2+\cdots+n_k=m} \prod_{i=1}^k \frac{1}{n_i (n_i+1)}$$ for a fixed value of$k$. The relationship to the expression in the question is that we can replace each$n_i\$ by ...

2

One solution might be ... Method 1. Define some variables: x = Table[Unique[], {5}]; Form the inner product and differentiate: D[Inner[Times, x, Range@Length@x], x[[2]]] 2 Or if you prefer it in a functional form: sum[n_] := Inner[Times, x[[1 ;; n]], Range@n] /; ( Length@x >= n) D[sum[4], x[[3]]] 3 Method 2. You could take a ...

2

As we should expect the following identity (maybe under some certain mathematical assumptions, I'm not sure): $$\sum _i \sum _j f(i,j)=\sum _i \left(\sum _j f(i,j)\right)\;\text{,}$$ which we can confirm in Mathematica 9 by the examples say: However, the nested-iterator version of the summation in the original question takes forever time in my ...

2

I think it's because in the sigma form the two sums are treated as a double sum with different order as the expression case: In==> $$\text{Hold}[\sum _{n=0}^{\infty } \sum _{k=n}^{\infty } \frac{1}{(k+2) k!}]//\text{InputForm}$$ Out==> Hold[Sum[1/((k + 2)*k!), {n, 0, Infinity}, {k, n, Infinity}]] and according to the documentation, the sum for n will ...

1

The first plot just works fine, although it takes a long time. Plot[q[2.0, 4.0, 0.2, t], {t, 0, 200}] The table contains the same values, because you sample the periodic function periodically. The data of the second plot is sampled badly. You should increase the frequency: ListPlot[Table[{t, qC[2, 4, 0.2, t]}, {t, 0, 20, .1}]] The last plot ...

1

I like image_doctor's solution better, but how about using Array and looking for the position using that index each time? Like this: xx = Array[x, 10, 1]; sum[n_] := Times[List @@ xx , Range[10]] sum[n] (* {x[1], 2 x[2], 3 x[3], 4 x[4], 5 x[5], 6 x[6], 7 x[7], 8 x[8], 9 x[9], 10 x[10]} *) Now sum[n_] := Times[List @@ xx^4, Range[10]] D[sum[n], ...

Only top voted, non community-wiki answers of a minimum length are eligible