Function Calculates the Probability of a Fibonacci Number

조회 수: 1 (최근 30일)
Sophie Culhane
Sophie Culhane 2020년 11월 2일
My task is to write a function that calculates the probability the the k-th digit of a Fibonacci Number in B is d. The elements of Prob are the probabilities of the k-th digit of a Fibonacci Number in B being d, for d = 0, 1, 2, ..., 9. n and k are positive integers and Prob is a 1x10 vector of probabilities. A is the set of the first n Fibonacci Numbers and B is the subset of the Fibonacci Numbers in A that have at least k digits. d is each of the digits 0-9. I have a small program written up, however I am stuck on where to go next. I know Prob has to be incoorporated somewhere, but I don't know where. Here is what I have so far:
function Prob = ex(n,k)
%
%
Prob = zeros(1,10);
A = zeros(1,n);
B = zeros(1,k);
position = 1;
while position <= n
if n < 3
Fn = 1;
else
Fn_2 = 1;
Fn_1 = 1;
for k = 3:n
Fn = Fn_1 + Fn_2;
Fn_2 = Fn_1;
Fn_1 = Fn;
end
end
position = position + 1;
end
% need to input d somewhere

답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by