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
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
krushnasamy subramaniyan
el 15 de Jun. de 2015
Respondida: charu sharma
el 27 de Ag. de 2015
"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
0 comentarios
Respuesta aceptada
Walter Roberson
el 15 de Jun. de 2015
Your code is not paying attention to the requirement,
If n is not a positive integer, the function returns an empty array.
0 comentarios
Más respuestas (1)
charu sharma
el 27 de Ag. de 2015
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
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!