[go: up one dir, main page]

Advertisement
MatsGranvik

Catalan numbers as convergents of power series.

Nov 25th, 2012
1,463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. Mathematica:
  2.  
  3. (*program start*)
  4. (*coefficients (coeff) in power series can be changed*)
  5. Clear[t, n, k, i, nn, x];
  6. coeff = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  7. 1}; mp[m_, e_] :=
  8. If[e == 0, IdentityMatrix@Length@m, MatrixPower[m, e]]; nn =
  9. Length[coeff]; cc = Range[nn]*0 + 1; Monitor[
  10. Do[Clear[t]; t[n_, 1] := t[n, 1] = cc[[n]];
  11. t[n_, k_] :=
  12. t[n, k] =
  13. If[n >= k,
  14. Sum[t[n - i, k - 1], {i, 1, 2 - 1}] -
  15. 0*Sum[t[n - i, k], {i, 1, k - 1}], 0];
  16. A4 = Table[Table[t[n, k], {k, 1, nn}], {n, 1, nn}];
  17. A5 = A4[[1 ;; nn - 1]]; A5 = Prepend[A5, ConstantArray[0, nn]];
  18. cc = Total[
  19. Table[coeff[[n]]*mp[A5, n - 1][[All, 1]], {n, 1, nn}]];, {i, 1,
  20. nn}], i]; cc
  21. (*Mats Granvik,Jul 11 2015*)
  22. (*program end*)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement