フィルターのクリア

Write a function called bell that returns the first n rows of the Bell triangle, where n is an input argument. The function must return an n-by-n array where the the top left triangle contains the Bell triangle with each row of the Bell triangle posi

1 回表示 (過去 30 日間)
"Write a function called bell that returns the first n rows of the Bell triangle, where n is an input argument. For a precise definition, see http://en.wikipedia.org/wiki/Bell_triangle. The function must return an n-by-n array where the top left triangle contains the Bell triangle with each row of the Bell triangle positioned diagonally—bottom-left-to-upper-right—and the bottom right triangle contains only zeros. If n is not a positive integer, the function returns an empty array.
program
function B = bell(n)
B(1,1) = 1;
for i=2:n
B(i,1) = B(1,end);
for j = 1:i-1
B(i-j,j+1) = B(i-j+1,j)+B(i-j,j);
end
end
end
error
Your function made an error for argument(s) -1
can any one help me advance wishes

採用された回答

Walter Roberson
Walter Roberson 2015 年 6 月 15 日
Your code is not paying attention to the requirement,
If n is not a positive integer, the function returns an empty array.

その他の回答 (1 件)

charu sharma
charu sharma 2015 年 8 月 27 日
You should add a condition to check if n is a positive integer or not. Here is a complete solution of this program: http://farzicoders.blogspot.in/2015/08/write-function-called-bell-that-returns.html

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by