Problem 55980. Generate Pascal's Triangle Matrix
Pascal's triangle is an arrangement of numbers where each value is the sum of the values adjacent to it in the previous row:
The values can also be calculated directly. The
value of the
row is
. For example, the fifth row is 1, 4, 6, 4, 1:
nchoosek(4,0)
ans =
1
nchoosek(4,1)
ans =
4
nchoosek(4,2)
ans =
6
nchoosek(4,3)
ans =
4
nchoosek(4,4)
ans =
1
Given a positive integer n, return an n-by-n matrix that represents the values of the first n rows of Pascal's triangle. The first k values of the kth row of the matrix will be the values from Pascal's triangle; the remaining n-k values should be 0.
For example, for n = 6, the output should be
1 0 0 0 0 0
1 1 0 0 0 0
1 2 1 0 0 0
1 3 3 1 0 0
1 4 6 4 1 0
1 5 10 10 5 1
Solution Stats
Problem Comments
Solution Comments
Show commentsGroup

Generate a point cloud
- 10 Problems
- 2 Finishers
- Generate a point cloud named `Simplex-Lattice Design`
- Generate a point cloud named `Incremental Lattice Design`
- Generate a point cloud on an equilateral triangle 1
- Generate a point cloud on an equilateral triangle 2
- Generate a point cloud on an equilateral triangle 3
- Generate a point cloud on an equilateral triangle 4
- Generate a point cloud on an equilateral triangle 5
- Generate a point cloud on an equilateral triangle 6
- Generate a point cloud on an equilateral triangle 7
- Generate a point cloud on an equilateral triangle 8
Problem Recent Solvers97
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!