Review questions for Final Exam
1.
A Pascal’s triangle with levels 0 to 4 is shown below. Level 0 has a single value, and each value on subsequent
levels is the sum of the two entries diagonally above in the previous level of the triangle. For example, the value
6 in level 4 is the sum of the values 3 and 3 in level 3.
1
11
121
1331
14641
.
.
.
level 0
level 1
level 2
level 3
level 4
Complete function
pascalVector
below to return the
row vector
corresponding to a speci±ed level of Pascal’s
triangle. For example, if level
lev
is 4, then the returned vector must be [1
,
4
,
6
,
4
,
1]. Assume that
lev
is a
nonnegative integer. The only
Matlab
builtin functions allowed are
zeros
,
ones
, and
length
.
Do not use the formula for binomial coeﬃcients to solve this problem. Use a loop (or loops): the vector for each
level is based on the vector from the previous level.
function p = pascalVector(lev)
% p is the vector corresponding to level lev of Pascal’s triangle
2.
C
is a cell array with three components: a real number, a vector of numbers, and a matrix of numbers.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '07
 FAN/VANLOAN
 Addition, Prime number, Lev, LEVEL LEVEL LEVEL

Click to edit the document details