Function Calculates the Probability of a Fibonacci Number

1 visualización (últimos 30 días)
Sophie Culhane
Sophie Culhane el 2 de Nov. de 2020
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

Respuestas (0)

Categorías

Más información sobre Mathematics 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!

Translated by