Following is my code, you can see that in eq[], its arguments are defined by t
and list{xs}
, If I expand the list{xs}
, I have to write a lot of λ
.
Could you help me to simplify the definition of eq[]?
When I wanna set λ from λ1 to λ1000, how can I achieve that?
Clear[n, λs, xs, tvalues]
n = 5;
λs = Symbol["λ" <> ToString[#]] & /@ Range[n](*number of sites*);
xs = Append[λs, β];
tvalues = Range[0., 1., 0.01] (*set of t values*);
randnum = RandomReal[1, {10, n + 1}];
Clear[eq]
eq[t_, {λ1_, λ2_, λ3_, λ4_, λ5_, β_}] =
Block[{U = 1., μ = 0.5, ϵ = (-2 t - 0.5), EE, summand},
EE[k_] := (-2 t ( Cos[(2 π (k - 1))/n])) - μ;
summand[λ_, k_] := (U/(2 n)) (Cosh[λ]^2 Sinh[λ]^2 +
2 Sinh[λ]^4 +
2 β^2 Cosh[λ] Sinh[λ] +
4 β^2 Sinh[λ]^2 ) + Sinh[λ]^2 EE[k];
Total[MapIndexed[summand[#, #2[[1]]] &, λs]] + ( β^2 ϵ) + (U/(2 n)) (β^4)
];
```
x[i]
instead of forcingx1, x2,...
withToString
. The let the function accept aList
argument, instead of specifying the elements of the list explicitly in the argument pattern. $\endgroup$