I used this code to find the number of even elements in the Fibonacci Sequence up to a given number 'd'.
function y = evenFibo(d)
k = 0;
for i = 1:1:d
a = fibonacci(i);
if rem(a,2)==0
k = k+1;
else
k = k+0;
end
end
y = k;
end
But , it's repeatedly showing that "Undefined function 'fibonacci' for input arguments of type 'double'". How can I solve this problem?

Antworten (1)

James Tursa
James Tursa am 9 Apr. 2018
Bearbeitet: James Tursa am 9 Apr. 2018

1 Stimme

The fibonacci( ) function was introduced in R2017a. What version of MATLAB are you running?
If you are running an earlier version, try this FEX submission from John D'Errico:

1 Kommentar

I'm using R2018a, it's working fine in my PC, but whenever I try to submit for Cody problems, the problem I mentioned earlier occurs

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by