Tag Info

New answers tagged

1

If you know the kappa values ahead of time (eg. {1,2,3,4,5} ) and the dimension of your getA matrix is 3, for example kappa = Range[5]; n=3; then use a Pure Function and Map it to the List of kappa values getA[#] & /@ kappa getW[IdentityMatrix[3], getA[#], IdentityMatrix[3]] & /@ kappa { {{2, -1, -1}, {-1, 2, -1}, {-1, -1, 2}}, ...


3

One can certainly compute a[n] for arbitrary positive integer $n$. a[n_] := 1 - Sum[Binomial[n, k] 2^(n - k - 1) a[k], {k, 0, n - 2}] - 2 n a[n - 1]; a[0] := 1; a[1] := -1; a[2] := 3; a[15] (* $-694475294514315$ *) ListLogPlot[Table[a[i], {i, 1, 20}]] Just note that many values of a[i] are negative and won't show up on the ListLogPlot. However, ...


1

The key is in defining the pattern correctly. I would use something like this: Clear[f] f[terms : {_, _, _} ..] := terms which when used does this f[{1,2,3}] (* {1,2,3} *) f[{1,2,3}, {2,3,4}] (* Sequence[{1,2,3}, {2,3,4}] *) So, to make effective use of that pattern, I would then put it into a list, e.g. Clear[f] f[terms : {_, _, _} ..] := {terms} ...


0

Use BlankSequence in function definition, e.g. to get a list of all the first elements: f[triplets__] := {triplets}[[All, 1]] so you can use it as f[{a1, b1, c1}, {a2, b2, c2}] (* {a1, a2} *) Note that this doesn't actually restrict you to using triplets as arguments for f, just that you have to give it one or more arguments.


1

This seems to work. Use With to "inject" the inner definition into outer. Clear[inner]; inner = Compile[{{i, _Integer}, {j, _Integer}}, If[i >= j, 0, AppendTo[bag, list]; inner[i + 1, j]]]; Clear[outer]; outer = With[{inner = inner}, Compile[{{i, _Integer}}, Block[{list = ConstantArray[0, {i, 2}], bag}, bag = {list}; ...


3

Just for fun to do recursively in contrast to in-built binary graphs, e[n_] := {n <-> 2 n, n <-> 2 n + 1}; gf[grp_, n_, opts : OptionsPattern[]] := Module[{vl, ne, ng}, vl = Sort@VertexList[grp]; ne = Flatten[e /@ vl[[-n ;;]]]; ng = EdgeAdd[VertexAdd[grp, ne[[All, 2]]], ne]; Graph[VertexList[ng], EdgeList[ng], ...


1

If your are looking for a Binary tree than this may work for you: fnBTree[n_] := CompleteKaryTree[Sequence @@ # , VertexLabels -> "Name"] & /@ Join[{{1, 1}, {2, 1}}, Table[{i + 1, 2}, {i, n - 2}]] Call fnBTree with n=4 fnBTree[4]


1

A straightforward implementation T[{L_, k_}, d_, coeff_] /; k >= d := 0; T[{0, k_}, d_, coeff_] := -coeff[[k + 1]]; T[{L_, k_}, d_, coeff_] /; L > 0 := T[{L, k}, d, coeff] = coeff[[d + 1]] T[{L - 1, k + 1}, d, coeff] - coeff[[k + 1]] T[{L - 1, 0}, d, coeff] Owing to constants (from $a_0$, $a_1$, ..., $a_{d})$, so the $a_k$ should be written as ...


2

Use With to replace only explicit appearances of k in the right-hand-side, preventing the changing values of k from contaminating the stack. f[{_}] = 2.; f[n_] := f[n] = With[ {k = Union[Select[n, # > 1 &]]}, f[Drop[n, 1]] + If[k == {}, 0., Sum[Count[n, i]*f[Join[DeleteCases[n, i, 1, 1], i - 1]], {i, k}]] ] f[{1, 2, 2, 3, 3, 3}] ...



Top 50 recent answers are included