【问题标题】:Compute Bell numbers in Matlab在 Matlab 中计算贝尔数
【发布时间】:2015-05-28 22:28:41
【问题描述】:

这是我已经实现的:

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-1,j)+B(i,j);
    end
end
end

当 n=3 时,我得到:

 1     2     3
 1     3     0
 2     0     0

代替:

 1     2     5
 1     3     0
 2     0     0

【问题讨论】:

    标签: arrays matlab combinatorics


    【解决方案1】:

    你需要换行

    B(i-j,j+1) = B(i-1,j)+B(i,j);

    进入

    B(i-j,j+1) = B(i-j+1,j)+B(i-j,j);
    

    例如:n=5

    B =
         1     2     5    15    52
         1     3    10    37     0
         2     7    27     0     0
         5    20     0     0     0
        15     0     0     0     0
    

    按照this.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多