# Tag Info

10

Square brackets are only used for functions x = Range[4] (* {1, 2, 3, 4} *) y = NestList[RotateLeft, x, Length[x] - 1] (* {{1, 2, 3, 4}, {2, 3, 4, 1}, {3, 4, 1, 2}, {4, 1, 2, 3}} *) If the extra brackets are intended x = {Range[4]} (* {{1, 2, 3, 4}} *) y = {NestList[RotateLeft, x[[1]], Length[x[[1]]] - 1]} (* {{{1, 2, 3, 4}, {2, 3, 4, 1}, {3, 4, 1, 2},...

9

Permute[Range[4], CyclicGroup[4]] {{1, 2, 3, 4}, {2, 3, 4, 1}, {3, 4, 1, 2}, {4, 1, 2, 3}} You can also use RotateLeft: RotateLeft[Range[4], #] & /@ Range[0, 3] {{1, 2, 3, 4}, {2, 3, 4, 1}, {3, 4, 1, 2}, {4, 1, 2, 3}}

9

Permute exists for reordering lists. Permute[list, Cycles[{{1, 4}, {2, 5}, {3, 6}}]] This swaps entries $1 \leftrightarrow 4$, $2 \leftrightarrow 5$ and $3 \leftrightarrow 6$. The necessary permutation can be found using FindPermutation: FindPermutation[Range@9, {4, 5, 6, 1, 2, 3, 7, 8, 9}] Cycles[{{1, 4}, {2, 5}, {3, 6}}]

8

You can check whether the Head of the expression is Plus, which is associated with a non-factored polynomial: list = { 1 + x^2, (-1 + x) (1 + x + x^2), (1 + x)^2, 2 (2 + x + x^2), 2 (2 + x)^2 }; ClearAll[isF] isF[Times[_Integer, poly_]] := isF[poly] isF[poly_] := Head[poly] =!= Plus SetAttributes[isF, Listable] isF@...

8

x = Range[4]; Partition[x, Length[x], 1, 1] {{1, 2, 3, 4}, {2, 3, 4, 1}, {3, 4, 1, 2}, {4, 1, 2, 3}}

7

What you want is called "currying". Not involving new operators you may try: Clear[f, g] f[x_, y_] := x^2 + y^3 g[x_] = Evaluate[f[x, #]] &; f[3, 2] == 17 == g[3][2] ?? g However, MMA has a special operator CurryApplied for this: Clear[f, g] f[x_, y_] := x^2 + y^3 g = CurryApplied[f, 2]; f[3, 2] == 17 == g[3][2] ?? g You may want to also ...

7

At least shorter: Flatten@Partition[list, 3][[{2, 1, 3}]]

6

Edit SetAttributes[CircleDot, {Flat, OneIdentity}]; CircleDot[{x_, y_}, {a_, b_}] := {x ** θ[y] ** a, y ** b}; {g1,h1}⊙{g2, h2}⊙{g3, h3} {g1 ** θ[h1] ** g2 ** θ[h1 ** h2] ** g3, h1 ** h2 ** h3} Update SetAttributes[CircleDot, {Orderless, Flat, OneIdentity}]; CircleDot[{x_, y_}, {a_, b_}] := {x*θ[y]*a, y*b} {g1, h1}⊙{g2, h2}⊙{g3, h3} {g1 g2 g3 θ[h2] θ[h1 ...

5

aa = Table[{tab1[[i]][[1]], tab1[[i]][[2]], tab2[[j]][[1]], tab2[[j]][[2]]}, {i, 1, Length[tab1], 1}, {j, 1, Length[tab2], 1}]; // AbsoluteTiming // First 0.146368 You can use Outer: bb = Outer[Join, tab1, tab2, 1]; // AbsoluteTiming // First aa == bb 0.040488 True Or, if you have to execute it more often, you can Compile the code: cf = Compile[{{...

5

5

Id suggest using TakeList TakeList[ist, {{4, 6}, 3, All}] TakeList[ist, {{4, 6}, {1, 3}, {1, 3}}] The indices need to be relative to those elements that are not yet taken. If you have absolute indices given: ist = Range[20]; parts = {{5, 6}, {9, 13}, {1, 4}, {19, 20}, {14, 18}}; Catenate[ist[[# ;; #2]] & @@@ parts]

4

Here is an example. The condition is that k be at least equal to a+b. Since we cannot increment k we set the variable t to the value of k. The While increments t until it is equal or greater than a+b. At this point, just using t by itself will return the value of t. Clear[f]; f[a_, b_, k_ : 0] := Block[ {t}, t = k; While[t < a + b, t++]; t ...

4

ParametricPlot[{((1 - x^2)*Cos[θ] Sin[θ])/(Cos[θ]^2 + Sin[θ]^2*x^2), -(x/(Cos[θ]^2 + Sin[θ]^2*x^2))}, {θ, 0, π/2}, {x, 1, 10}, MeshFunctions -> {#3 &, #4 &}, MeshStyle -> {Red, Cyan}, Mesh -> 20, PlotStyle -> {Opacity[.1], Yellow}, PlotPoints -> 80]

4

Clear["Global*"] Show[ ListLinePlot[{{0, 1}, {1, 1}, {10, 10}}, PlotStyle -> Directive[Red, Dashed, Thickness[0.008]], Filling -> Top, FillingStyle -> Lighter[Gray, 0.85]], Plot[{2 Sin[x], 3 x - 2, x^2}, {x, 0, 3}, GridLines -> Automatic], PlotRange -> {{0, 3}, Automatic}] EDIT: To obscure the lines by the Filling(adjust ...

4

Instead of dealing with indices, try Sum[Piecewise[{{f[m, n], m^2 + n^2 != 0}, {0, True}}], {m, -Infinity, Infinity}, {n, -Infinity, Infinity}] It should be noticed the notation n,k is preferable over n,m which are similar.

4

I believe the relation you wrote is only valid for $n>2$. For $n=0,1,2$ you have to use the identities of eq.(2.31) in [1705.02909], \begin{aligned} t_{0,n_1,n_2\dots} &= Nt_{n_1,n_2},\\ t_{1,n_1,n_2\dots} &= 0,\\ t_{2,n_1,n_2\dots} &= \frac{N^2-1+n_1+n_2+\dots}{2}t_{n_1,n_2,\dots}. \end{aligned} The code below ...

4

I think one way to do this is: Select[mytup, !(#[[8]] == -1 && #[[9]] == 1 && MemberQ[mytup, # * {1, -1, 1, 1, -1, 1, 1, -1, -1}]) &] This keeps exactly the ones that fail the criterion, i.e. deletes the ones that do satisfy having their 8th part be -1, their 9th part be 1, and such that the list contains some member equal ...

3

Why not use InterpolatingPolynomial? For your example: Expand @ InterpolatingPolynomial[ {{0, 1}, {1, 2}, {2, 4}, {3, 8}, {4, 16}}, x ] 1 + (7 x)/12 + (11 x^2)/24 - x^3/12 + x^4/24

3

Legended[Show[ Plot[{2 Sin[x], 3 x - 2, x^2}, {x, 0, 3}, GridLines -> Automatic], ListLinePlot[{{0, 1}, {1, 1}, {10, 10}}, PlotStyle -> Directive[Red, Dashed, Thickness[0.008]], Filling -> Top, FillingStyle -> Opacity[0.75, LightGray]]], Placed[Column@{SwatchLegend[{Opacity[.5, LightGray], White}, {"Above", "...

3

This is what immediate assignments are for: f[x_] = D[x^100*E^(2*x^5)*Cos[x^2], {x, 137}] (* long output (can be suppressed with semicolon) *) f[3.] (* -8.90666869434476*10^664 *) See here for a tutorial on the distinction between = and :=.

3

You get no result because Vi is a function. If you replace Vi, say Vi0 by a constant you will get a solution that is not unique. But if you restrict the solutions to Reals you will get a unique results. Here is the procedure: Clear["Global*"]; q = (((1602176634)/10^9))*10^(-19); k = (((1380649)/10^6))*10^(-23); \[Eta] = 3/2; Td = 20 + (5463/20); ...

3

As it was suggested by @CarlWoll and @thorimur in the comments, I evaluated: (9.2 - 8)/1.2 // FullForm which returns: 0.9999999999999994` I'm not really sure why, but I suspect that this is related to the order in which Mathematica evaluates each operation. Since 9.2/1.2 and 8/1.2 have no finite decimal expansion, apparently Mathematica truncates this ...

3

If you include a list of time series as first argument of DateListPlot you will get a plot with multiple curves. Here is an example where I plot "TTM" and "Quarterly" of the given company in the same plot. For clarity, I first create the time series separately and subsequently feed them to DateListPlot: ds1 = Entity["Company", &...

3

The U.S. National Imagery and Mapping Agency (NIMA) (formerly the Defense Mapping Agency) adopted a special grid for military use throughout the world called the Universal Transverse Mercator (UTM) grid. In this grid, the world is divided into 60 north-south zones, each covering a strip 6° wide in longitude. These zones are numbered consecutively beginning ...

2

Include Print["opt=", OptionValue@symbols]; in your function and you will see, that the options are already evaluated. Therefore, you need a function with one of the Hold Attributs: HoldFirst, HoldRest, HoldAll,... to get the symbole name, not its value. Here is one way to do it: ClearAll[freshStart]; SetAttributes[freshStart, HoldFirst] freshStart[...

2

Conversion of comments to a community wiki answer: Michael E2: Try = instead of := or use Evaluate in pad[t_] := Evaluate[PadeApproximant[..]]. thorimur: If you're wondering why that suggestion of @MichaelE2 works, it's because := does not evaluate its right hand side before substituting. So pad[1] substitutes 1 verbatim into PadeApproximant[t Log[t], {t, 1, ...

2

tup4a = Join @@@ Tuples[{tup1, tup3}]; tup4a // Short {{0,-1,-1,0,-1,-1,d,0,0},{0,-1,-1,0,-1,-1,d,0,1},<<2912>>, {1,1,1,1,1,1,d,-1,1},{1,1,1,1,1,1,d,-1,-1}} tup4b = Distribute[{tup1, tup3}, List, List, List, Join]; tup4a == tup4b True "to get that directly from tup1 and tup2": tup4c = Join @@@ Tuples[{tup1, {{d}}, tup2}]; tup4a ...

2

FilledCurve work for Line. line = Line[{{0, 1}, {1, 1}, {10, 10}, {0, 10}}]; Plot[{2 Sin[x], 3 x - 2, x^2}, {x, 0, 3}, GridLines -> Automatic, Epilog -> {{Gray, Opacity[.5], FilledCurve[line]}, Directive[Red, Dashed, Thickness[0.008]], Line[{{0, 1}, {1, 1}, {10, 10}}]}]

2

Construct a polygon using the coordinates of the epilog line: Plot[{2 Sin[x], 3 x - 2, x^2}, {x, 0, 3}, GridLines -> Automatic, Epilog -> {Directive[Red, Dashed, Thickness[0.008]], Line[{{0, 1}, {1, 1}, {10, 10}}], LightGray, Opacity[.5], Polygon[{{0, 1}, {1, 1}, {10, 10}, Scaled[{0, 1}, {10, 10}], Scaled[{0, 1}, {0, 1}]}]}]

2

You can do Sum[If[n == 0 && m == 0,0, f[m,n]],{m,-Infinity,Infinity},{n,-Infinity,Infinity}]

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