Using nested loops to calculate Bernoulli numbers

조회 수: 1 (최근 30일)
matlab noob69
matlab noob69 2019년 12월 4일
편집: matlab noob69 2019년 12월 4일
I am not familar with MATLAB, can anyone please help me out with this question, much thanks.
Write a script that uses nested for loops to calculate the first eleven Bernoulli numbers, store them in an array, then display the result.
Annotation 2019-12-04 071400.png

채택된 답변

Raj
Raj 2019년 12월 4일
B=zeros(1,11); % Create an empty array to store the Bernoulli numbers
for m=0:10 % Number of Bernoulli numbers required
temp2=0;
for k=0:m % outer summation
temp1=0;
for v=0:k % inner summation
temp1=temp1+ (((-1)^v)*(factorial(k)/(factorial(v)*factorial(k-v)))*((v^m)/(k+1)));
end
temp2=temp2+temp1;
end
B(m+1)=temp2; % Store
end
B %Display result
"not familar with MATLAB" - Start here.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by