
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Class: Introduction to Computing Using MATLAB; Subject: Computer Science; University: Cornell University; Term: Unknown 2008;
Typology: Exams
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Review questions for the final exam
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 .. .
level 0 level 1 level 2 level 3 level 4
Complete function pascalVector below to return the row vector corresponding to a specified 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 non-negative integer. The only Matlab built-in functions allowed are zeros, ones, and length.
Do not use the formula for binomial coefficients 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
6 5 is prime 4 3 is prime
function MyHistogram(v) % Draw a histogram for the data in v using asterisks in the COMMAND WINDOW (not figure window). % v is a vector of non-negative values. % The histogram is scaled so that the largest data value is represented by % ten asterisks. Round as necessary in order to draw whole asterisks. % Example: v = [12 4.1 0.5 9.2 20] % Output in Command Window: % ****** % ** % % ***** % **********