これの続き
N=6;
B=zeros(1,N);
B(1,1) = 1;
disp(B(1,1));
for i = 2:1:N
B(1,i) = getBernoulliNumber(i, B);
disp(B(1,i));
end
function Bn = getBernoulliNumber(n, B)
Bn = 0;
for k = 0:n-2
Bn = Bn + nCr(n, k) * B(k+1);
end
Bn = -Bn / n;
end
function num = exponentiation(j)
num = 1;
for i = 1:j
num = num * i;
end
end
function result = nCr(n, r)
result = exponentiation(n) / (exponentiation(r) * exponentiation(n - r));
end
コメント