Simple question about functions

function nFib = fib(n)
a = (1 + sqrt(sym(5)))/2;
nFib = (a^n)-((-a)^(-n)) / sqrt(sym(5)) ;
end
*The output for this function when n=3 is
fib(3)
ans =
5^(1/2)/(5*(5^(1/2)/2 + 1/2)^3) + (5^(1/2)/2 + 1/2)^3
Why isn't the answer showing the number but just the entire function itself? And how can I solve this problem to show the actual answer(in number)? Thank you!

 Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 30 de Ag. de 2016
function nFib = fib(n)
a = (1 + sqrt(5))/2;
nFib = a^n-(-a)^(-n) / sqrt(5) ;
end

2 comentarios

Danny C
Danny C el 30 de Ag. de 2016
Now it's working. Would you mind telling me what was wrong in my function?
Andrei Bobrov
Andrei Bobrov el 30 de Ag. de 2016
I replaced the symbolic expression (sym(5)) to a value of integer 5.

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Etiquetas

Preguntada:

el 30 de Ag. de 2016

Editada:

el 2 de Sept. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by