This page is READ-ONLY. It is generated from the old site.
All timestamps are relative to 2013 (when this page is generated).
If you are looking for TeX support, please go to VietTUG.org

Pascal Triangle

Ví dụ cung cấp bởi Phương Nam ở #978.

 1 \documentclass{article}
 2 \usepackage{tikz}
 3 
 4 \makeatletter
 5 \newcommand\binomialCoefficient[2]{%
 6     % Store values 
 7     \[email protected]@counta=#1% n
 8     \[email protected]@countb=#2% k
 9     %
10     % Take advantage of symmetry if k > n - k
11     \[email protected]@countc=\[email protected]@counta%
12     \advance\[email protected]@countc by-\[email protected]@countb%
13     \ifnum\[email protected]@countb>\[email protected]@countc%
14         \[email protected]@countb=\[email protected]@countc%
15     \fi%
16     %
17     % Recursively compute the coefficients
18     \[email protected]@countc=1% will hold the result
19     \[email protected]@countd=0% counter
20     \pgfmathloop% c -> c*(n-i)/(i+1) for i=0,...,k-1
21         \ifnum\[email protected]@countd<\[email protected]@countb%
22         \multiply\[email protected]@countc by\[email protected]@counta%
23         \advance\[email protected]@counta by-1%
24         \advance\[email protected]@countd by1%
25         \divide\[email protected]@countc by\[email protected]@countd%
26     \repeatpgfmathloop%
27     \the\[email protected]@countc%
28 }
29 \makeatother
30 
31 Các bạn có thể dùng đoạn mã sau để tạo ra tam giác Pascal. Trong đoạn mã này, tôi xét $(a + b)^n$ và xét với $n = 10$.
32 \begin{document} 
33 \begin{tikzpicture}
34 \foreach \n in {0,...,10} {
35   \foreach \k in {0,...,\n} {
36     \node at (\k-\n/2,-\n) {$\binomialCoefficient{\n}{\k}$};
37   }
38 }
39 \end{tikzpicture}
40 
41 \end{document}